POJ 1284 primitive roots
2016-08-28 09:45
246 查看
/* 题目描述:给出奇质数p,问p的原根有多少个? 思路:根据原根的性质,质数p的原根数量为phi(p - 1) */ #pragma warning(disable:4786) #pragma comment(linker, "/STACK:102400000,102400000") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stack> #include<queue> #include<map> #include<set> #include<vector> #include<cmath> #include<string> #include<sstream> #define LL long long #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define mem(a,x) memset(a,x,sizeof(a)) #define lson l,m,x<<1 #define rson m+1,r,x<<1|1 using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double PI = acos(-1.0); const double eps=1e-6; const int maxn = 65540; int phi[maxn]; void Euler(int n) { mem(phi , 0); phi[1] = 1; for(int i = 2 ; i<= n ; i++){ if(phi[i]) continue; for(int j = i ; j<= n ; j += i){ if(!phi[j]) phi[j] = j; phi[j] = phi[j] / i * ( i - 1 ) ; } } } int main() { int p ; Euler(65538); while(scanf("%d",&p)!=EOF){ printf("%d\n",phi[p - 1]); } return 0; }
相关文章推荐
- poj 1284 Primitive Roots
- POJ-1284 Primitive Roots(原根的个数定理)
- POJ 1284 Primitive Roots 原根个数
- POJ 1284 Primitive Roots (欧拉函数&原根定理)
- poj 1284 Primitive Roots(原根+欧拉函数)
- poj1284 Primitive Roots(原根,欧拉函数)
- poj - 1284 - Primitive Roots
- poj 1284 Primitive Roots
- POJ 1284 Primitive Roots
- poj 1284——Primitive Roots
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
- POJ 1284 Primitive Roots(欧拉函数)
- 【POJ1284】Primitive Roots 欧拉函数
- poj 1284 Primitive Roots(原根+欧拉函数)
- POJ 1284 Primitive Roots【欧拉函数】
- POJ 1284 Primitive Roots(欧拉函数)
- POJ 1284:Primitive Roots 求原根的数量
- POJ 1284 Primitive Roots 数论原根。
- 【POJ 1284】Primitive Roots
- POJ 1284 Primitive Roots (欧拉函数--求原根数量)