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 }(xi​modp)∣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(素数原根的个数)的更多相关文章

  1. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

  2. poj 1284 Primitive Roots(原根+欧拉函数)

    http://poj.org/problem?id=1284 fr=aladdin">原根 题意:对于奇素数p,假设存在一个x(1<x<p),(x^i)%p两两不同(0&l ...

  3. POJ 1284 Primitive Roots 数论原根。

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2479   Accepted: 1385 D ...

  4. POJ 1284 Primitive Roots 原根

    题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...

  5. POJ 1284 Primitive Roots (求原根个数)

    Primitive Roots 题目链接:id=1284">http://poj.org/problem?id=1284 利用定理:素数 P 的原根的个数为euler(p - 1) t ...

  6. (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))

    /* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...

  7. POJ 1284 Primitive Roots (欧拉函数+原根)

    <题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...

  8. poj 1284 Primitive Roots(未完)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3155   Accepted: 1817 D ...

  9. poj 1284 Primitive Roots

    从来没有接触过完全剩余系,不会证明,知道看了别人的题解才知道要用欧拉函数: 下面是证明过程: p是奇素数,如果{xi%p | 1 <= i <= p - 1} = {1,2,...,p-1 ...

随机推荐

  1. vim必备

    1. 复制 将vim中整个文件内容复制到系统剪贴板--gg"+yG  2. 格式化 缩进格式化代码--gg=G

  2. Ubuntu 14 如何解压 .zip、.rar 文件

    .zip 和 .rar 是Windows下常用的压缩文件,在Ubuntu中如何解压. [解压.zip文件] Ubuntu中貌似已经安装了unzip软件,解压命令如下: unzip ./FileName ...

  3. 【Core】.NET Core中读取App.config配置文件

    1.项目中添加App.config文件 因为.NET Core的项目本质是控制台应用,所以ConfigurationManager的API会去默认读取app.config配置文件,而不是web.con ...

  4. js实现往数组中添加非存在的对象,如果存在就改变键值。

    let arr = [] // 数组中元素数据类型为{name: 'bb', age: 12} // 现在需求是,将每次获得的新对象{name: '', age: }push到数组arr中,但前提是数 ...

  5. 第 8 章 容器网络 - 069 - Calico 的默认连通性

    相同calico 网络之间的连通性 测试一下 bbox1 与 bbox2 的连通性: ping 成功,数据包流向如下图所示. 1)根据 bbox1 的路由表,将数据包从 cal0 发出. 2)数据经过 ...

  6. html缓存控制

  7. Steam饥荒

    存档回滚 D:\Program Files (x86)\Steam\userdata\***\219740\remote 巨人国是survival_数字,海难是shipwreck_数字,哈姆雷特是po ...

  8. Flask之项目创建,路由以及会话控制

    Flask Flask诞生于2010年,是Armin ronacher(人名)用 Python 语言基于 Werkzeug 工具箱编写的轻量级Web开发框架. Flask 本身相当于一个内核,其他几乎 ...

  9. python自动化测试入门篇-postman

    接口测试基础-postman 常用的接口有两种:webservice接口和http api接口. Webservice接口是走soap协议通过http传输,请求报文和返回报文都是xml格式. http ...

  10. PAT 1065 A+B and C (64bit)

    1065 A+B and C (64bit) (20 分)   Given three integers A, B and C in [−], you are supposed to tell whe ...