fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool cPrime(int n)
  5. {
  6. if(n < 2) return 0;
  7. for(int i = 2; i * i <= n; i++){
  8. if(n % i == 0) return 0;
  9. }
  10. return 1;
  11. }
  12.  
  13. int tongcs(int n)
  14. {
  15. int res = 0;
  16. while(n){
  17. res += n % 10;
  18. n /= 10;
  19. }
  20. return res;
  21. }
  22. long long ans;
  23.  
  24. void Try(int n)
  25. {
  26. if(cPrime(n)){
  27. ans += tongcs(n);
  28. return;
  29. }
  30. for(int i = 2; i * i <= n; i++){
  31. if(n % i == 0){
  32. Try(i);
  33. if(i != (n / i)) Try(n / i);
  34. }
  35. }
  36. }
  37. int main()
  38. {
  39. int n;
  40. cin >> n;
  41. Try(n);
  42. cout << ans;
  43. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
286