您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: