题解:欧拉函数
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n; int ans=0; int phi[100000]; int vis[100000]={0}; int prime[100000],cntprime=0; int Lineshake(){ vis[1]=1;phi[1]=1; for(int i=2;i<=n;++i){ if(!vis[i]){ prime[++cntprime]=i; phi[i]=i-1; } for(int j=1;(j<=cntprime)&&(i*prime[j]<=n);++j){ vis[i*prime[j]]=1; if(i%prime[j]==0){ phi[i*prime[j]]=phi[i]*prime[j]; break; } phi[i*prime[j]]=phi[i]*(prime[j]-1); } } } int main(){ scanf("%d",&n); Lineshake(); for(int i=2;i<=n-1;++i)ans=ans+phi[i]*2; printf("%d\n",ans+3); return 0; }