Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <bitset>
  3. #define Nmax 1000001
  4. #define RUP ios::sync_with_stdio(false); f.tie(0); g.tie(0);
  5. #define TOT f.close(); g.close();
  6. using namespace std;
  7.  
  8. ifstream f("bookface.in");
  9. ofstream g("bookface.out");
  10.  
  11. int P[Nmax/3] , np;
  12. bool E[Nmax];
  13.  
  14. inline long long putere(long long n , long long e);
  15.  
  16. int main()
  17. {
  18. RUP
  19.  
  20. E[1] = E[0] = 1;
  21.  
  22. for(int i = 2 ; i * i <= Nmax ; i++)
  23. if(E[i] == false)
  24. for(int j = i * i ; j <= Nmax ; j += i)
  25. E[j] = true;
  26.  
  27. for(int i = 2 ; i < Nmax ; i++)
  28. if(E[i] == false)
  29. P[++np] = i;
  30.  
  31. int n;
  32. long long x , s = 1;
  33.  
  34. f >> n;
  35.  
  36. for(int i = 1 ; i <= n ; i++)
  37. {
  38. f >> x;
  39. s = 1;
  40.  
  41. int d = 1 , e = 1;
  42.  
  43. while(x > 1)
  44. {
  45. if(x % P[d] == 0)
  46. {
  47. e = 0;
  48.  
  49. while(x % P[d] == 0)
  50. x /= P[d] , e++;
  51.  
  52. e *= 2;
  53.  
  54. s = s * (putere(P[d] , e + 1) - 1) / (P[d] - 1);
  55. }
  56. else
  57. d++;
  58.  
  59. if(P[d] * P[d] > x && x > 1)
  60. s = s * (putere(x , 3) - 1) / (x - 1) , x = 1;
  61. }
  62.  
  63. g << s << "\n";
  64.  
  65. }
  66. TOT
  67. }
  68. inline long long putere(long long n , long long e)
  69. {
  70. long long p = 1;
  71.  
  72. for(int i = 1 ; i <= e ; i++)
  73. p *= n;
  74.  
  75. return p;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement