首页 > 其他 > 详细

poj 1284 Primitive Roots(原根)

时间:2014-09-09 11:12:28      阅读:311      评论:0      收藏:0      [点我收藏+]

定理:假如一个数x有原根,则元根的个数为phi(phi(x)),phi(x)为小于x且与x互质的正整数个数。

#include <iostream>
#include <cmath>
using namespace std;
int p;
int f(int x){
    int ans=x;
    int m=sqrt(x+0.5);
    for(int i=2;i<=m;i++)if(x%i==0){
        ans=ans/i*(i-1);
        while(x%i==0)x/=i;
    }
    if(x>1)ans=ans/x*(x-1);
    return ans;
}
int main()
{
    while(cin>>p)cout<<f(f(p))<<endl;
    return 0;
}

  

poj 1284 Primitive Roots(原根)

原文:http://www.cnblogs.com/wshh/p/3961565.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!