poj1284 Primitive Roots
来源:互联网 发布:理财软件哪款靠谱 编辑:程序博客网 时间:2024/05/17 22:19
We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (x i mod p) | 1 <= i <= p-1 } is equal to { 1, ..., p-1 }. For example, the consecutive powers of 3 modulo 7 are 3, 2, 6, 4, 5, 1, and thus 3 is a primitive root modulo 7.
Write a program which given any odd prime 3 <= p < 65536 outputs the number of primitive roots modulo p.
Write a program which given any odd prime 3 <= p < 65536 outputs the number of primitive roots modulo p.
Each line of the input contains an odd prime numbers p. Input is terminated by the end-of-file seperator.
For each p, print a single number that gives the number of primitive roots in a single line.
233179
10824
求原根的。
哪些数有原根?
n = 1,2,4,p^r,2p^r。期中p为奇素数,r为任意的正整数。
原根的一些性质:
•一个数n如果有原根,那么有phi(phi(n))个
•高斯证明了:
•一个数n的全体原根乘积模n余1
•一个数n的全体原根总和模n余μ(n-1)(莫比乌斯函数)
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 70000;int prim[MAXN],phi[MAXN];bool vis[MAXN];int tot;void get_phi(){ phi[1] = 1; tot = 0; for(int i = 2; i < MAXN; ++i) { if(!vis[i]) { prim[tot++] = i; phi[i] = i-1; } for(int j = 0; j < tot; ++j) { if(prim[j]*i > MAXN)break; vis[i*prim[j]] = 1; if(i%prim[j] == 0) { phi[i*prim[j]] = phi[i] * prim[j]; break; } else phi[i*prim[j]] = phi[i]*phi[prim[j]]; } }}int main(){ int n; get_phi(); while(~scanf("%d",&n)) { printf("%d\n",phi[phi[n]]); } return 0;}
阅读全文
0 0
- POJ1284 Primitive Roots
- poj1284 Primitive Roots (数论)
- poj1284 Primitive Roots
- POJ1284 Primitive Roots
- POJ1284 Primitive Roots
- poj1284 Primitive Roots
- poj1284 Primitive Roots 【原根】
- POJ1284 Primitive Roots【原根】
- poj1284 Primitive Roots 原根个数
- 【POJ1284】Primitive Roots——欧拉数
- poj1284 Primitive Roots (欧拉函数)
- POJ1284 Primitive Roots(原根定理)
- POJ1284---Primitive Roots(求原根个数, 欧拉函数)
- Primitive Roots(Poj1284)(欧拉函数+原根)
- poj1284——Primitive Roots(欧拉函数)
- poj1284 Primitive Roots(原根,欧拉函数)
- poj1284 Primitive Roots:欧拉函数+原根
- POJ1284 Primitive Roots (欧拉函数 & 原根)
- 邪能炸弹
- css选择器
- Java变量的声明、初始化和作用域
- HDU
- C语言各种数据类型取值范围
- poj1284 Primitive Roots
- 呼叫中心KPI
- python之禅
- UVa806 习题6-8 空间结构(Spatial Structures,ACM/ICPC World Finals 1998)
- 遗传算法(4):交叉概率和变异概率的自适应化
- bzoj1096 [ZJOI2007]仓库建设(斜率优化)
- Linux查看服务命令与端口使用状态
- xmlhttp.status为0的原因及其解决方案
- python3中使用builtwith以及各种疑难问题的方法