开始补我不敢碰的数论QAQ
看了资料感觉还是很晕,先把结论记下吧。。
若(x,y)符合提议gcd(x-1,y-1)=1,那么先欧拉筛法求出s=sigma(phi[i]),然后注意(1,2)(2,1)(2,2)3个点,答案就是2*s+1了
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(int i=l;i<=r;i++) 3 #define dec(i,l,r) for(int i=l;i>=r;i--) 4 #define link(x) for(edge *j=h[x];j;j=j->next) 5 #define mem(a) memset(a,0,sizeof(a)) 6 #define inf 1e9 7 #define ll long long 8 #define succ(x) (1<<x) 9 #define NM 40000+5 10 using namespace std; 11 int read(){ 12 int x=0,f=1;char ch=getchar(); 13 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 14 while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); 15 return x*f; 16 } 17 int phi[NM],p[NM],n,tot,check[NM]; 18 ll s; 19 int main(){ 20 freopen("data.in","r",stdin); 21 n=read(); 22 s=phi[1]=1; 23 inc(i,2,n-1){ 24 if(!check[i]){ 25 p[++tot]=i; 26 phi[i]=i-1; 27 } 28 s+=phi[i]; 29 inc(j,1,tot){ 30 if(i*p[j]>n)break; 31 check[i*p[j]]++; 32 if(i%p[j])phi[i*p[j]]=phi[i]*phi[p[j]]; 33 else{ 34 phi[i*p[j]]=phi[i]*p[j]; 35 break; 36 } 37 } 38 } 39 // inc(i,1,n)printf("%d ",phi[i]);printf("\n"); 40 printf("%lld\n",s*2+1); 41 return 0; 42 }