luogu_2158 [SDOI2008]仪仗队
Posted Code_Together
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luogu_2158 [SDOI2008]仪仗队相关的知识,希望对你有一定的参考价值。
//欧拉函数:
欧拉函数是积性函数——若m,n互质
![技术分享](https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D140/sign=daa516337cec54e745ec1e1a89399bfd/bd3eb13533fa828b5d8406eefa1f4134970a5a1c.jpg)
特殊性质:当n为奇数时,
![技术分享](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D96/sign=52a5c55ef1246b607f0ebe72eaf8e29d/8cb1cb134954092331f8f8739558d109b3de492e.jpg)
若n为质数则
![技术分享](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D85/sign=31100df17bd98d1072d40134203fd0be/a5c27d1ed21b0ef404180353dac451da80cb3ece.jpg)
#include <cstdio> #include <iostream> using namespace std; const int N=40010; int n,p[N],nop[N],cnt,phi[N],ans; int main(){ scanf("%d",&n); if(n==0){puts("0"); return 0;} nop[1]=1; for(int i=2;i<=n;i++){ if(!nop[i]){p[++cnt]=i; phi[i]=i-1;} for(int j=1;j<=cnt && i*p[j]<=n;j++){ nop[i*p[j]]=1; if(i%p[j]==0){phi[i*p[j]]=phi[i]*p[j]; break;} else phi[i*p[j]]=phi[i]*(p[j]-1); } } for(int i=2;i<=n-1;i++)ans+=phi[i]; printf("%d\n",ans*2+3); return 0; }
以上是关于luogu_2158 [SDOI2008]仪仗队的主要内容,如果未能解决你的问题,请参考以下文章