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