欧拉筛模板题
#include<cstdio>
using namespace std;
const int N=40003;
int num=0,prime[N],phi[N];
bool notp[N];
inline void shai(int n){
phi[1]=1;
for(int i=2;i<=n;++i){
if (!notp[i]){
prime[++num]=i;
phi[i]=i-1;
}
for(int j=1;j<=num&&i*prime[j]<=n;++j){
notp[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]*phi[prime[j]];
}
}
}
int main(){
int n;
scanf("%d\n",&n);
shai(n-1);
int ans=0;
for(int i=1;i<n;++i)
ans+=phi[i];
printf("%d\n",ans*2+1);
return 0;
}
这样就可以啦~~~