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. 通过python的hashlib模块计算一个文件的MD5值

    Python的hashlib提供了很多摘要算法,如MD5,SHA1等常用算法. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(如MD5值 ...

  2. jquery之div模拟textarea文本域轻松实现高度自适应

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. synchronized同步方法《二》

    1.synchronized方法和锁对象 (1).验证线程锁的是对象 代码如下: 1.1创建一个MyObject类: package edu.ymm.about_thread4; public cla ...

  4. vue extend 的基本使用

    vue.extend 局部注册 的应用2 请注意,extend创建的是一个组件构造器,而不是一个具体的组件实例.所以他不能直接在new Vue中这样使用: new Vue({components: f ...

  5. [Hibernate] official tutorial - userguide

    Persistence contexts org.hibernate.Session API and javax.persistence.EntityManager API represent a c ...

  6. 批量压缩 css js 文件 包含多个文件 自动识别

    注意事项  css 注释压缩不会造成影响      因为是块注释     当然也可以选择去注释压缩 js 带注释压缩  要注意注意 注意  //行注释会造成 压缩后的代码在一行 导致注释后的代码都失效 ...

  7. [hdu P4081] Qin Shi Huang’s National Road System

    [hdu P4081] Qin Shi Huang’s National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  8. 海量日志采集Flume(HA)

    海量日志采集Flume(HA) 1.介绍: Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据 ...

  9. day12_python_1124

    00 如何学习python 如何学好英语? 母系英语. 听 说 读 写 练 input output 听 说 读 写(练) 听,读 说 纠正 01 昨日内容回顾 生成器:本质就是迭代器,自己用pyth ...

  10. leetcode python 012 hard 合并k个有序链表

    #[LeetCode] Merge k Sorted Lists 合并k个有序链表(升序) import numpy as npimport time class Node(object):    d ...