poj 1284 求原根
来源:互联网 发布:mysql事物隔离级别 编辑:程序博客网 时间:2024/05/29 14:57
题目大意:给出一个奇素数,求出他的原根的个数,定义n的原根x满足条件0<x<n,并且有集合{ (xi mod n) | 1 <= i <=n-1 } 和集合{ 1, ..., n-1 }相等
关于这道题。如果知道欧拉函数的话,看出的答案是phi(n-1)其实也不难
关于这道题。如果知道欧拉函数的话,看出的答案是phi(n-1)其实也不难
定理:如果p有原根,则它恰有φ(φ(p))个不同的原根,p为素数,当然φ(p)=p-1,因此就有φ(p-1)个原根
直接用euler打表:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#include<map>using namespace std;const int maxn = 100000 + 10;#define INF 0x3f3f3f3f#define clr(x,y) memset(x,y,sizeof x )typedef long long ll;#define eps 10e-10const ll Mod = 1000000007;typedef pair<ll, ll> P;int euler[maxn];void Init(){ euler[1] = 1; for(int i = 2; i < maxn; i ++) euler[i] = i; for(int i = 2; i < maxn; i ++) if(euler[i] == i) for(int j = i ; j < maxn; j += i) euler[j] = euler[j] /i *(i - 1);}int main(){ int n; Init(); while( ~ scanf("%d",&n)) { printf("%d\n",euler[n -1]); } return 0;}
阅读全文
0 0
- poj 1284 求原根
- poj 1284
- POJ 1284
- POJ 1284 Primitive Roots (求原根个数)
- POJ 1284:Primitive Roots 求原根的数量
- 欧拉函数:poj 2407, poj 1284,poj 2478,poj 3090,poj 3696,poj 3358
- poj 1284 Primitive Roots(求原根的个数)
- POJ 1284-Primitive Roots(欧拉函数求原根个数)
- POJ 1284 Primitive Roots (欧拉函数--求原根数量)
- 原根 poj 1284
- poj 1284 原根
- POJ 1284 Primitive Roots
- poj - 1284 - Primitive Roots
- Poj 1284 Primitive Roots
- 原根 poj 1284
- 【POJ 1284】Primitive Roots
- POJ 1284 primitive roots
- POJ 1284Primitive Roots
- ajax开发:ajax详解
- CSS设置页面滚动条的样式
- 分治法,动态规划及贪心算法区别
- python 删除指定时间间隔之前的文件
- PCB电路板周围那一圈过孔或金属包边是做啥用的
- poj 1284 求原根
- static 与 extern
- 指针数组和数组指针的区别
- 图解 Android 事件分发机制
- 2017年PHP培训机构排名
- 互联网架构(1):并发编程--多线程基础
- 修改编辑文件夹名称, put数据出现的问题
- 量化策略平台
- Web.xml配置详解之context-param