poj-1284(欧拉函数+原根)
来源:互联网 发布:java 调用执行jar包 编辑:程序博客网 时间:2024/06/05 18:32
问题描叙:
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.
Input
Each line of the input contains an odd prime numbers p. Input is terminated by the end-of-file seperator.
Output
For each p, print a single number that gives the number of primitive roots in a single line.
Sample Input
233179Sample Output
10824
题目题意:题目给我们一个奇素数,让我们求有多少个x满足the set { (x i mod p) | 1 <= i <= p-1 } is equal to { 1, ..., p-1 }.
题目分析:其实这个题目实质就是问p有多少个原根(哎,想要学好数论,得见多识广啊!)
下面是百度对原根的解释:
对于这个题目来说有俩点重要的原根性质
1:模m有原根的充要条件是m= 1,2,4,p,2p,p^n,其中p是奇质数,n是任意正整数。
2:对正整数(a,m) = 1,如果 a 是模 m 的原根,那么 a 是整数模n乘法群(即加法群 Z/mZ的可逆元,也就是所有与 m 互素的正整数构成的等价类构成的乘法群)Zn的一个生成元。由于Zn有 φ(m)个元素,而它的生成元的个数就是它的可逆元个数,即 φ(φ(m))个,因此当模m有原根时,它有φ(φ(m))个原根。
个人实力太差了,不能给大家解释了(还得赶紧多学点才行)
我们就记住吧!模m有原根,m=1,2,4,p,2p,p^n,p是奇质数,当模m有原根时,原根的个数是φ(φ(m))(这个是欧拉函数)
因为这个题目给的n是奇素数,所以phi[n]=n-1,因为n与1到n-1都互质。
答案就是phi[n-1]
代码如下:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int get_euler(int n){ int res=n,a=n; for (int i=2;i*i<=a;i++) { if (a%i==0) { res=res/i*(i-1); while (a%i==0) a=a/i; } } if (a>1) res=res/a*(a-1); return res;}int main(){ int n; while (scanf("%d",&n)!=EOF) { printf("%d\n",get_euler(n-1)); } return 0;}
- poj-1284(欧拉函数+原根)
- POJ 1284 Primitive Roots (原根,欧拉函数)
- POJ 1284 Primitive Roots 原根(欧拉函数)
- POJ 1284 Primitive Roots (欧拉函数&原根定理)
- poj 1284 Primitive Roots(欧拉函数,原根定理)
- poj 1284 Primitive Roots(原根+欧拉函数)
- POJ 1284 : Primitive Roots - 欧拉函数,原根
- 欧拉函数 素数原根 POJ 1284
- POJ 1284 原根(欧拉函数)
- POJ 1284 Primitive Roots(原根个数与欧拉函数)
- Primitive Roots +欧拉函数+原根
- poj1284Primitive Roots【欧拉函数 原根】
- HDU 6051原根 + 欧拉函数
- poj1284(欧拉函数、原根)
- 原根,欧拉函数,欧拉定理,费马小定理
- poj-1284 欧拉函数
- Primitive Roots(Poj1284)(欧拉函数+原根)
- poj1284 Primitive Roots(原根,欧拉函数)
- eclipse或myeclipse快速定义变量的快捷键
- 一不小心搞出来的空指针
- 层次分析法用法和概念
- CS231n课程笔记翻译:图像分类笔记(上)
- 在Angular2.0 或 Angular4.0 中使用Jquery
- poj-1284(欧拉函数+原根)
- MySQL存储过程调试工具-dbForge Studio for MySQL
- Netty入门学习
- android gradle tools 3.X 中依赖,implement、api 指令
- 第三十七篇:JAVA访问数据库之连接数据库
- GridView频道管理
- 随机梯度下降与批梯度下降
- netscope——caffe的prototxt模型文件可视化工具
- Ionic控件 Button