fork download
  1. //Lib
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<ctime>
  7.  
  8. #include<iostream>
  9. #include<algorithm>
  10. #include<vector>
  11. #include<string>
  12. #include<queue>
  13. #include<stack>
  14. #include<set>
  15. #include<map>
  16. using namespace std;
  17. //Macro
  18. #define rep(i,a,b) for(int i=a,tt=b;i<=tt;++i)
  19. #define drep(i,a,b) for(int i=a,tt=b;i>=tt;--i)
  20. #define erep(i,e,x) for(int i=x;i;i=e[i].next)
  21. #define irep(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
  22. #define read() (strtol(ipos,&ipos,10))
  23. #define sqr(x) ((x)*(x))
  24. #define pb push_back
  25. #define PS system("pause");
  26. typedef long long ll;
  27. typedef pair<int,int> pii;
  28. const int oo=~0U>>1;
  29. const double inf=1e100;
  30. const double eps=1e-6;
  31. string name="", in=".in", out=".out";
  32. //Var
  33. int n,p[10000],cnt,ans;
  34. bool vis[40008];
  35. void GetPrime()
  36. {
  37. for(int i=2;i*i<=40000;i++)
  38. {
  39. if(!vis[i])p[++cnt]=i;
  40. for(int j=1;j<=cnt&&i*p[j]<=40000;j++)
  41. {
  42. vis[i*p[j]]=true;
  43. if(i%p[j]==0)break;
  44. }
  45. }
  46. }
  47. int phi(int x)
  48. {
  49. int ret=x;
  50. for(int i=1;i<=cnt&&p[i]*p[i]<=x;i++)
  51. {
  52. if(x%p[i]==0)
  53. {
  54. ret-=ret/p[i];
  55. while(x%p[i]==0)x/=p[i];
  56. if(x==1)break;
  57. }
  58. }
  59. if(x!=1)ret-=ret/x;
  60. return ret;
  61. }
  62. void Work()
  63. {
  64. GetPrime();
  65. scanf("%d",&n);
  66. rep(i,1,n-1)
  67. ans+=phi(i);
  68. cout<<ans*2+1<<endl;
  69. }
  70. int main()
  71. {
  72. // freopen((name+in).c_str(),"r",stdin);
  73. // freopen((name+out).c_str(),"w",stdout);
  74. // Init();
  75. Work();
  76. return 0;
  77. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty