fork download
  1. /// Heil Hitler :P
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <string>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <cstdlib>
  9. #include <algorithm>
  10. #include <new>
  11. #include <vector>
  12. #include <stack>
  13. #include <queue>
  14. #include <map>
  15. #include <set>
  16. #define CLR(o) memset(o, 0x00, sizeof o)
  17. #define CLR1(o) memset(o, -1, sizeof o)
  18. #define MAX3(a, b, c) MAX(a , MAX(b,c))
  19. #define MIN3(a, b, c) MIN(a , MIN(b,c))
  20. #define takei(a) scanf("%d", &a)
  21. #define takell(a) scanf("%lld", &a)
  22. #define takellu(a) scanf("%llu", &a)
  23. #define sf scanf
  24. #define ssf sscanf
  25. #define pb push_back
  26. #define PPP system("pause")
  27. #define ok cout << "OK" <<endl;
  28. #define pf printf
  29. #define PI 2*acos(0)
  30. #define READ(a) freopen(a,"r",stdin);
  31. #define WRITE(b) freopen(b, "w", stdout);
  32. using namespace std;
  33.  
  34. template <class T> T MAX(T a, T b) { return a>b?a:b;}template <class T> T MIN(T a, T b) { return a<b?a:b;}
  35. template <class T1> void deb(T1 p) { cout << "Debugging: " << p << endl;}
  36. template <class T1, class T2> void deb(T1 p, T2 q) { cout << "Debugging: " << p << "\t" << q << endl;}
  37. template <class T1, class T2, class T3> void deb(T1 p, T2 q, T3 r) { cout << "Debugging: " << p << "\t " << q << "\t " << r << endl;}
  38. template <class T1, class T2, class T3, class T4> void deb(T1 p, T2 q, T3 r, T4 s) { cout << "Debugging: " << p << "\t " << q << "\t " << r << "\t " << s << endl;}
  39. const int xx[] = {0, 0, 1, -1, -1, 1, -1, 1};const int yy[] = {1, -1, 0, 0, 1, 1, -1, -1}; const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2}; const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1}; // KX-> Knight moovs xx-> diagonal -> 8 horizontal/vertical->4
  40. #define SIZE 4000009
  41. long long *phi;
  42.  
  43. void PHII()
  44. {
  45. phi = new long long[SIZE];
  46. int i, j, k, l;
  47. for(i=2; i<SIZE; i++)
  48. phi[i] = i;
  49. for(i=2; i<SIZE; i++)
  50. if(phi[i]==i)
  51. {
  52. for(j=i; j<SIZE; j+=i)
  53. phi[j] -= phi[j]/i;
  54. }
  55. //for(i=2; i<13; i++) deb(i, phi[i]);
  56. }
  57.  
  58. int main()
  59. {
  60. // time_t t1=clock();
  61. #ifndef ONLINE_JUDGE
  62. READ("input.txt");
  63. //WRITE("output.txt");
  64. #endif
  65. /// MAIN
  66. PHII();
  67. long long i, j, k, l, a, b, c, *p;
  68. p = new long long[SIZE];
  69. CLR(p);
  70. for(i=2; i<4000001; i++)
  71. {
  72. p[i]+=phi[i]+p[i-1];
  73. for(j=i*2, k=2; j<4000001; j+=i, k++)
  74. {
  75. p[j] += (i*phi[k]);
  76. }
  77. }
  78. while(sf("%lld", &i)==1 &&i)
  79. pf("%lld\n", p[i]);
  80. delete(p);
  81. delete(phi);
  82. /* Coding is FUN */
  83. /// ENDD
  84. // time_t t2=clock();
  85. // cout << " My time: " <<(t2-t1) << endl;;
  86. return 0;
  87. }
  88.  
  89.  
Success #stdin #stdout 3.25s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty