fork download
  1. #include <bits/stdc++.h>
  2. #define boost ios_base::sync_with_stdio(0); cin.tie(0);
  3. using namespace std;
  4.  
  5. #define ll long long
  6.  
  7. vector<ll> p;
  8.  
  9. void sang(int n) {
  10. bool t[n + 5];
  11. for (int i = 2; i * i <= n; i++)
  12. if (t[i] == false)
  13. for (int j = i * i; j <= n; j += i)
  14. t[j] = true;
  15. for (int i = 2; i <= n; i++)
  16. if (t[i] == false)
  17. p.push_back(i);
  18. }
  19.  
  20. ll power(ll x, ll n) {
  21. ll p = 1;
  22. for (; n > 0; n >>= 1, x *= x)
  23. if (n & 1)
  24. p *= x;
  25. return p;
  26. }
  27.  
  28. ll s(ll n) {
  29. ll s = 1;
  30. for (ll i : p) {
  31. if (i * i > n) break;
  32. if (n % i == 0) {
  33. int d = 0;
  34. while (n % i == 0)
  35. d++, n /= i;
  36. s *= (pow(i, d + 1) - 1) / (i - 1);
  37. }
  38. }
  39. if (n > 1)
  40. s *= (n + 1);
  41. return s;
  42. }
  43.  
  44. int main() {
  45. boost;
  46. sang(1000000);
  47. int t = 1;
  48. cin >> t;
  49. while (t--) {
  50. ll n; cin >> n;
  51. cout << s(n) << "\n";
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5300KB
stdin
5
4
6
12
9
10
stdout
7
12
28
13
18