Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define mx 4000002
- using namespace std;
- int phi[mx];
- long long ans[mx];
- void EulerPhi()
- {
- int i,j;
- for(i=1;i<mx;i++)
- {
- phi[i] = i;
- }
- for(i=2;i<mx;i++)
- {
- if(phi[i]==i)
- {
- for(j=i;j<mx;j+=i)
- {
- phi[j]-=phi[j]/i;
- }
- }
- }
- }
- void generateAns()
- {
- int i,j;
- for(i=1;i<mx;i++)
- {
- for(j=i+i;j<mx;j+=i)
- {
- ans[j]+=i*phi[j/i];
- }
- }
- for(i=2;i<mx;i++)
- {
- ans[i]+=ans[i-1];
- }
- }
- int main()
- {
- EulerPhi();
- generateAns();
- int n;
- while(scanf("%d",&n)&&n)
- {
- printf("%lld\n",ans[n]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment