Advertisement
999ms

Untitled

Oct 1st, 2020
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) begin(x), end(x)
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. int get_cnt(int x) {
  8.     int ans = 0;
  9.     while (x > 0) {
  10.         ans += x % 10;
  11.         x /= 10;
  12.     }
  13.     return ans;
  14. }
  15.  
  16. int main() {
  17.     int x;
  18.     cin >> x;
  19.     while (x >= 10) {
  20.         x = get_cnt(x);
  21.     }
  22.     cout << x << '\n';4
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement