51 Nod 1135 原根
来源:互联网 发布:打开xlsx文件的软件 编辑:程序博客网 时间:2024/06/05 07:59
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根。(其中φ(m)表示m的欧拉函数)
给出1个质数P,找出P最小的原根。
Input
输入1个质数P(3 <= P <= 10^9)
Output
输出P最小的原根。
Input示例
3
Output示例
2
/*求素数的最小原根.由定理a^i==1(mod)时(i<p) 当且仅当i==p-1 成立 则a为p的原根.把p-1质因数分解,然后每次检验(p-1)/pi.复杂度看起来好像有点高,但是还是呲呲的2333(毕竟原根比较多,so......如果p不是素数的话,把p-1换成phi(p)即可.*/#include<iostream>#include<cmath>#define MAXN 100001#define LL long longusing namespace std;int a[MAXN],tot,ans,p;void pre(){ int tmpp=p-1; for(int i=2;i<=sqrt(tmpp);i++) { if(tmpp%i==0) { while(tmpp%i==0) tmpp/=i; a[++tot]=i; } if(tmpp==1) break; } if(tmpp>1) a[++tot]=tmpp;}int mi(LL a,int b){ LL tot=1; while(b) { if(b&1) tot=tot*a%p; a=a*a%p; b>>=1; } return tot;}bool check(int x){ for(int i=1;i<=tot;i++) if(mi(x,(p-1)/a[i])==1) return false; return true;}void slove(){ for(int i=2;i<p;i++) if(check(i)){ans=i;break;}}int main(){ cin>>p; pre();slove(); cout<<ans; return 0;}
0 0
- 51nod 1135 原根
- 51nod 1135 原根
- 【51nod 1135 原根】
- 51nod-1135:原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51 Nod 1135 原根
- 51 NOD 1135 原根
- 51nod 1135原根
- 51Nod 1135 原根
- 51nod 1135 原根
- 51nod 1135 原根
- 51Nod-1135-原根
- 51nod 1135 原根
- 51Nod 1135 原根
- 51Nod-1135-原根
- 50个jQuery代码段帮你成为更出色的JS开发者
- 采用Build模式构建自定义Dialog
- python3异常
- Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web
- TCP编程的一个小例子
- 51 Nod 1135 原根
- 类模板的非类型形参
- MongoDB启动时出现errno:111 Connection refused错误的解决
- 蓝桥杯 黄金连分数
- 【Spring学习08】依赖配置:复合属性
- Java的方法和方法重载
- Freemarker判断序列中是否包含某个元素
- SQLServer2008数据迁移
- SVM (草稿运算)