P2158 [SDOI2008] 仪仗队
#include<cstdio> #include<iostream> #include<algorithm> #define il inline #define ri register #define pc(i) putchar(i) using namespace std; const int N=4e4+2; int n,phi[N],prime[N],cnt,ans=3; bool isprime[N]; il void pre() { isprime[1]=true,phi[1]=1; for(ri int i=2;i<n;++i) { if(!isprime[i]) prime[++cnt]=i,phi[i]=i-1; ans+=phi[i]*2; for(ri int j=1;j<=cnt&&i*prime[j]<=n;++j) { isprime[i*prime[j]]=true; if(i%prime[j]) phi[i*prime[j]]=phi[i]*phi[prime[j]]; //n与pi互质 else {phi[i*prime[j]]=phi[i]*prime[j];break;} //n'包含了n的所有质因子 } } } int main() { ios::sync_with_stdio(false); cin>>n; if(n==1) return printf("0"),0; pre(),cout<<ans; return 0; }
标签:pre,函数,int,il,include,ri,欧拉,define From: https://www.cnblogs.com/zxyc/p/16799155.html