51nod 1135 原根
来源:互联网 发布:外贸邮件群发软件 编辑:程序博客网 时间:2024/06/14 10:31
题目链接
原根相关知识:
http://blog.csdn.net/zhang20072844/article/details/11541133
——AndyZhang
(感谢原Po写得很详细)
题意:求一个质数 P 的最小原根 (P <= 1e9)
方法见上面链接
AC代码如下:
#include <bits/stdc++.h>int n, p[100010], tot;typedef long long LL;LL poww(LL a, LL b) { LL ret = 1; while (b) { if (b & 1) ret = ret * a % n; a = a * a % n; b >>= 1; } return ret;}bool check(int x) { int nn = n - 1; for (int i = 0; i < tot; ++i) { if (poww(x, nn / p[i]) == 1) return false; } return true;}void work() { tot = 0; int nn = n - 1; for (int i = 2; i * i <= nn; ++i) { if (nn % i == 0) { p[tot++] = i; while (nn % i == 0) nn /= i; } } if (nn > 1) p[tot++] = nn; for (int i = 1; i < n; ++i) { if (check(i)) { printf("%d\n", i); return; } }}int main() { while (scanf("%d", &n) != EOF) work(); 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-原根
- dip与px相互转换工具类
- 配置 maven 编译的 JDK 版本
- Android系统版本与版本代号中英文名字
- Node读写JSON
- CodeForces
- 51nod 1135 原根
- 解决 “Uncaught SyntaxError: Unexpected end of JSON input” 可能有用的方法
- jQuery自定义事件之trigger事件
- XStream 用法详解 java 类与 XML 互换
- ubuntu下安装Firefox中国版解决Ubuntu与Windows下Firefox账号同步问题
- hdu6069
- java md5工具类
- 常用正则表达式及评注
- CCF推荐的国际学术会议