POJ 1284:Primitive Roots(素数原根的个数)
Primitive Roots
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5709 Accepted: 3261
Description
We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set (ximodp)∣1≤i≤p−1{ (x_i mod p) | 1 \leq i \leq p-1 }(ximodp)∣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
23
31
79
Sample Output
10
8
24
题意
给出一个正素数p,求p的原根的个数
思路
原根的定义: 对于两个正整数(a,m)=1(a,m)=1(a,m)=1,由欧拉定理可知:存在d≤m−1d\leq m-1d≤m−1。比如说欧拉函数d=φ(m)d=φ(m)d=φ(m),即小于等于mmm的正整数与mmm互质的正整数的个数,使得ad≡1(modm)a^d\equiv1 (mod m)ad≡1(modm)。由此,在(a,m)=1(a,m)=1(a,m)=1时,定义aaa对模mmm的指数δm(a)\delta m(a)δm(a)为使ad≡1(modm)a^d\equiv1(mod m)ad≡1(modm)成立的最小正整数ddd。由前知δm(a)\delta m(a)δm(a)一定小于等于φ(m)φ(m)φ(m),若δm(a)=φ(m)\delta m(a)=φ(m)δm(a)=φ(m),则称aaa为mmm的原根
原根个数定理: 如果ppp有原根,则它恰有φ(φ(p))φ(φ(p))φ(φ(p))个不同的原根,ppp为素数时,φ(p)=p−1φ(p)=p-1φ(p)=p−1,因此就有φ(p−1)φ(p-1)φ(p−1)个原根
AC代码
#include <iostream>
using namespace std;
int Eular(int n)
{
int eu=n;
for (int i=2;i*i<=n;i++)
{
if(n%i==0)
{
eu-=eu/i;
while(n%i==0)
n/=i;
}
}
if(n>1) //n本身也是个质因子
eu-=eu/n;
return eu;
}
int main(int argc, char const *argv[])
{
int p;
while(cin>>p)
{
cout<<Eular(p-1)<<endl;
}
return 0;
}
POJ 1284:Primitive Roots(素数原根的个数)的更多相关文章
- poj 1284 Primitive Roots (原根)
Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS Memory Limit: 10000K Descr ...
- poj 1284 Primitive Roots(原根+欧拉函数)
http://poj.org/problem?id=1284 fr=aladdin">原根 题意:对于奇素数p,假设存在一个x(1<x<p),(x^i)%p两两不同(0&l ...
- POJ 1284 Primitive Roots 数论原根。
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2479 Accepted: 1385 D ...
- POJ 1284 Primitive Roots 原根
题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...
- POJ 1284 Primitive Roots (求原根个数)
Primitive Roots 题目链接:id=1284">http://poj.org/problem?id=1284 利用定理:素数 P 的原根的个数为euler(p - 1) t ...
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...
- POJ 1284 Primitive Roots (欧拉函数+原根)
<题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...
- poj 1284 Primitive Roots(未完)
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3155 Accepted: 1817 D ...
- poj 1284 Primitive Roots
从来没有接触过完全剩余系,不会证明,知道看了别人的题解才知道要用欧拉函数: 下面是证明过程: p是奇素数,如果{xi%p | 1 <= i <= p - 1} = {1,2,...,p-1 ...
随机推荐
- Codeforces 438E The Child and Binary Tree - 生成函数 - 多项式
题目传送门 传送点I 传送点II 传送点III 题目大意 每个点的权值$c\in {c_{1}, c_{2}, \cdots, c_{n}}$,问对于每个$1\leqslant s\leqslant ...
- Python作业
1使用while 循环输入1,2,3,4,5,6,,8,9,10 count = 0 while count<10: count+=1 if count ==7: continue print( ...
- HTML基础【2】:基础标签
H系列标签(H1 ~ H6) 作用: 用于给文本添加标题语义 格式: <h1>xxxxxx</h1> 注意点 H 标签是用来给文本添加标题语义的,而不是用来修改文本的样式的 H ...
- idea基于hibernate生成的Entitle对象,会忽略外键属性
需要自己手动添加 如 private String cgcode; @Basic @Column(name = "cgcode") public String getCgcode( ...
- 《温故而知新》JAVA基础七
抽象类 定义:抽象类前面使用abstract关键字修饰(只用语被继承) 应用场景: 在父类中写一些子类中即将实现的方法,具体的实现在子类中写,也可以将多种特征相同的类抽离出来 使用规则 abstrac ...
- sqldeveloper 重置java.exe路径方法
sqldeveloper重新配置java.exe 1.进入D:\app\product\11.2.0\dbhome_1\sqldeveloper\sqldeveloper\bin路径下,找到sqlde ...
- Docker安装Tomcat镜像并部署web项目
一.安装Tomcat 1.查找Docker Hub上的tomcat镜像 docker search tomcat 2.拉取官方的镜像 docker pull tomcat 等待下载完毕,需要一些时间. ...
- Maven的pom配置文件
1.1 Maven的pom配置文件 1.1.1 pom文件内容和作用 Pom.xml文件用来设置项目的项目依赖.插件.项目版本等信息,其中必须的是xml的根元 ...
- linux软件管理之rpm管理rpm包
使用RPM工具管理RPM包 ====================================================================================需要 ...
- 『TensorFlow』张量拼接_调整维度_切片
1.tf.concat tf.concat的作用主要是将向量按指定维连起来,其余维度不变:而1.0版本以后,函数的用法变成: t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, ...