fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long sol(long long N) {
  5. while (N >= 10) {
  6. long long res = 0;
  7. while (N > 0) {
  8. res += N % 10;
  9. N /= 10;
  10. }
  11. N = res;
  12. }
  13. return N;
  14. }
  15.  
  16. int main() {
  17. long long N;
  18. cin >> N;
  19. cout << sol(N);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
1