51nodoj 1135 (原根)
来源:互联网 发布:人工智能有关英语作文 编辑:程序博客网 时间:2024/06/04 20:08
1135 原根
基准时间限制: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
推荐大神博客好了, 自己不会写,也不算太懂这里写链接内容
#include <cstdio>#include <cstring>#define M 10010#define LL long longint prime[M], cnt;void getprime(int n){ cnt = 1; for(int i=2; i<=n; i++) { if(n % i == 0) { prime[cnt++] = i; while(n % i == 0) { n /= i; } } } if(n > 1) { prime[cnt++] = n; }}LL quickpow(LL n, LL m, LL mod){ n %= mod; LL res = 1; while(m) { if(m & 1) { res = res * n % mod; } n = n * n % mod; m >>= 1; } return res;}int main(){ LL n; bool ok; while(scanf("%lld", &n) != EOF) { getprime(n-1);//求出 n-1 的所有的质因数 for(LL i=2; i<=n; i++) { ok = 1; for(LL j=1; j<cnt; j++) { if(quickpow(i, (n-1)/prime[j], n) == 1) //快速幂,判断是否有不符合的 { ok = 0; break; } } if(ok)//有成立的就直接输出 { printf("%lld\n", i); break; } } } return 0;}
0 0
- 51nodoj 1135 (原根)
- 51nodoj (大鱼吃小鱼---栈)
- 51nodoj 1256(逆元再探)
- 51nodoj 1174(RMQ)
- 51nodoj 1384(全排列)
- 51nodoj 1079 (中国剩余定理)
- 51 nodoj 最大矩阵和(动态规划入门篇)
- 51nodoj 1240(莫比乌斯函数)
- 51nodoj 1136 (容斥定理 || 欧拉函数)
- 51nodoj 1272 最大距离(最大循环节)
- 51nod--1135 原根 (数论)
- 51nod 1135 原根 (数论)
- 51nod 1135 原根 (数论)
- 51nod 1135 原根(求素数最小原根)
- 51nod 1135 原根 就是原根...
- 51nod 1135 原根
- 51nod 1135 原根
- 【51nod 1135 原根】
- Junit 单元测试 @Before @After。。。
- 关于内存管理思考方式的一些学习总结
- 将eclipse变得更加漂亮
- 求海量数据的topK问题
- STM32F100X RCC_APB2Periph_AFIO--复用IO时钟的使用
- 51nodoj 1135 (原根)
- scala 运行计时 App scala.time
- Filter过滤器学习总结
- stm32学习笔记 系统时钟
- lightoj 1042 Secret Origins(位运算符号的应用)
- 判断二叉树是否平衡 java
- tes
- stm32笔记:Systick系统滴答定时器
- Ubuntu 和 VMware tools文件夹共享问题