POJ1284:Primitive Roots——题解
生活随笔
收集整理的這篇文章主要介紹了
POJ1284:Primitive Roots——题解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?http://poj.org/problem?id=1284
給一個奇質數p,求p的原根數量。
有一個結論:當正整數n存在原根時,其一共有phi(phi(n))個不同余的原根。
所以答案為phi(p-1)。
#include<algorithm> #include<iostream> #include<cstring> #include<cctype> #include<cstdio> #include<cmath> #include<stack> using namespace std; typedef long long ll; const int N=70010; int phi[N],su[N]; bool he[N]; void Euler(int n){phi[1]=1;int tot=0;for(int i=2;i<=n;i++){if(!he[i]){su[++tot]=i;phi[i]=i-1;}for(int j=1;j<=tot;j++){int p=su[j];if(i*p>n)break;he[i*p]=1;if(i%p==0){phi[i*p]=phi[i]*p;break;}else phi[i*p]=phi[i]*phi[p];}} } int main(){int n;Euler(N-10);while(scanf("%d",&n)!=EOF){printf("%d\n",phi[n-1]);}return 0; }+++++++++++++++++++++++++++++++++++++++++++
+本文作者:luyouqi233。 +
+歡迎訪問我的博客:http://www.cnblogs.com/luyouqi233/?+
+++++++++++++++++++++++++++++++++++++++++++
轉載于:https://www.cnblogs.com/luyouqi233/p/8990764.html
總結
以上是生活随笔為你收集整理的POJ1284:Primitive Roots——题解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小爱音箱怎么设置
- 下一篇: nginx日志中添加请求的respons