标签:== c++ cout out include oid lse void visit
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn=4e6+100; int phi[maxn]; int prime[maxn]; int visit[maxn]; int tot=0; int num[maxn]; int ans[maxn]; void build_phi(int n) { phi[1]=1; for(int i=2;i<=n;i++) { if(!visit[i]) { prime[++tot]=i; phi[i]=i-1; } for(int j=1;j<=tot && i*prime[j]<=n;j++) { visit[i*prime[j]]=1; if(i%prime[j]==0) { phi[i*prime[j]]=phi[i]*prime[j]; break; } else { phi[i*prime[j]]=phi[i]*(prime[j]-1); } } } } void solve(int n) { for(int i=1;i<=n;i++) for(int j=i*2;j<=n;j+=i) num[j] += phi[j/i]*i; for(int i=2;i<=n;i++) { ans[i]=ans[i-1]+num[i]; } } int32_t main() { build_phi(maxn); solve(maxn); //cout<<phi[1000000]<<endl; int n; while(cin>>n&&n) { cout<<ans[n]<<endl; } return 0; }
gcd(1,n)+gcd(2,n)....gcd(n-1,n); Uva11426
标签:== c++ cout out include oid lse void visit
原文地址:https://www.cnblogs.com/Andromeda-Galaxy/p/9825100.html