fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4.  
  5.  
  6. int solution(ll n)
  7. {
  8. ll result = 1; // Initialize result as 1
  9. for (int p=2; p*p<=n; p++)
  10. {
  11. int power = 0;
  12. while(n%p==0)
  13. {
  14. n /= p;
  15. power++;
  16. }
  17. result *= (pow(p, power + 1.0) - 1) / (p-1);
  18. }
  19. if (n!=1) result *= (pow(n,2.0) - 1) / (n-1);
  20. return result;
  21. }
  22.  
  23. int main()
  24. {
  25. ios::sync_with_stdio(false);
  26.  
  27. int tc;
  28. ll num;
  29. cin>>tc;
  30. while(tc--)
  31. {
  32. cin>>num;
  33. cout<<solution(num)<<endl;
  34. }
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3464KB
stdin
2
6
5
stdout
12
6