fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. using namespace std;
  10. #define all(v) (v.begin()), (v.end())
  11.  
  12. void fast_io(){
  13. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  14. }
  15.  
  16. int main()
  17. {
  18. fast_io();
  19. long long n=0;
  20. cin >> n;
  21. // prime factorization
  22. long long factorSize = sqrt(n)+1;
  23. long long factors[factorSize] = {0};
  24. while (!(n%2)){
  25. n /= 2;
  26. factors[2]++;
  27. }
  28. for (int i = 3; i <= sqrt(n); i+=2){
  29. if (n%i == 0){
  30. n /= i;
  31. factors[i]++;
  32. }
  33. }
  34. factors[n]++;
  35.  
  36. /* geometric sequence
  37.   - (2^0 + 2^1 + 2^2 + 2^3)
  38.   - An = (2)^(n-1)
  39.   - Sn = a(r^n - 1)/(r - 1)
  40.  
  41.   // the multiplication of the prime factor's gemetric squence is the formula
  42.   //∏k(∑i=0akpik)
  43.  
  44.   For example, the sum of all of the factors of 120=23⋅3⋅5 is
  45.   (1+2+22+23)(1+3)(1+5)=15⋅4⋅6=360
  46.   */
  47.  
  48. long long sum = 1;
  49.  
  50. for (int i = 0; i < factorSize; i++){
  51. if (factors[i] == 0){continue;}
  52. int n = factors[i]+1;
  53. long long Sn = (pow(i, n) - 1)/(i-1);
  54. sum *= Sn;
  55. }
  56. cout << sum << endl;
  57. }
Success #stdin #stdout 0s 5272KB
stdin
12
stdout
28