fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int SumOfDigit(int n) {
  6. int f = 0;
  7. while (n >= 1) {
  8. f += n % 10;
  9. n /= 10;
  10. }
  11. return f;
  12. }
  13.  
  14.  
  15. int main()
  16. {
  17. int N;
  18. cin >> N;
  19. for (int i = 1; i <= N; i++) {
  20. int A;
  21. cin >> A;
  22. int sum = 0;
  23. double f = sqrt(A);
  24. for (int j = 1; j*1.0 <= f; j++) {
  25. if (A%j == 0) sum += SumOfDigit(j) + SumOfDigit(A/j);
  26. }
  27. if ((int) f == f) sum-=f;
  28. cout<<sum<<endl;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3460KB
stdin
2 2 10
stdout
3
9