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 ...
随机推荐
- selenium+java利用AutoIT实现文件上传
转自https://www.cnblogs.com/yunman/p/7112882.html?utm_source=itdadao&utm_medium=referral 1.AutoIT介 ...
- Python将list中的string批量转化成int/float
data = ['] data = map(eval, data) print data 输出:[1, 3.2, 2] 但是在Python3下我们输入: ls=[1,2,3] rs=map(str,l ...
- oracle 连接问题汇总
遇到的情况: 1/后台配置完好,若是连其他的库都是好的,当连接另外的库时,始终连接不上,这是需要考虑到服务端安装文件tnsnames文件中服务名在客户端的安装文件tnsnames文件中是否存在
- sublime设置html在浏览器打开
1.快捷键 Ctrl+Shift+P输入:pcip选择第一个 2.输入:View In Browser安装此插件 3.菜单栏Preferences->Key Bindings 输入:[{ &q ...
- RN中API之NetInfo--浅谈
我们在做移动端项目和手机APP应用时,避免不了要获取用户手机的网络状况.在使用RN技术开发APP时,其内置的NetInfo API就是为了解决这一问题的.下面简单的讲下NetInfo如何使用. 最新的 ...
- Redis学习--key的通用操作、移库操作、订阅与事务、持久化和总结
key的通用操作 keys pattern: pattern *表示任意一个多个字符 ?表示任意一个字符 del key1 key2 删除多个key exists keyname 查看是否存在 ren ...
- Verification of Model Transformations A Survey of the State-of-the-Art 模型转换的验证 对现状的调查
模型驱动工程范式认为软件开发生命周期由工件(需求规范.分析和设计文档.测试套件.源代码)支持,这些工件是表示要构建的系统不同视图的模型.存在一个由模型转换驱动的(半)自动构造过程,从系统的抽象模型开始 ...
- SecureCRT自动断开
解决方法 可以通过两个入口进行设置: 1.右击Session中的连接,选择Properties->Terminal->Anti-idle->勾选Send protocol NO-OP ...
- js数组和数组去重的几种简单的方法
http://blog.csdn.net/liangklfang/article/details/49300417 1.证明一个对象是数组的方法. 方法(1) [].constructor === A ...
- 『TensorFlow』张量拼接_调整维度_切片
1.tf.concat tf.concat的作用主要是将向量按指定维连起来,其余维度不变:而1.0版本以后,函数的用法变成: t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, ...