一、题目

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

23
31
79

Sample Output

10
8
24

二、题意分析

原根并不像百度介绍的那样,需要深入去研究。直接上干货,《初等数论及应用》(第六版)P260 定理9.5

如果正整数n有一个原根,那么它一共有φ(φ(n))个不同的原根。

对应该题目,因为给的p是奇素数,所以答案就是φ(p-1)。

三、代码

#include <iostream>
#include <cstring>
using namespace std; const int MAXN = 66000;
int Prime[MAXN], nPrime;
bool isPrime[MAXN]; void make_prime()
{
memset(isPrime, 1, sizeof(isPrime));
nPrime = 0;
isPrime[0] = isPrime[1] = 0;
for(int i = 2; i < MAXN; i++)
{
if(isPrime[i])
Prime[nPrime++] = i;
for(int j = 0; j < nPrime && (long long)i*Prime[j] < MAXN; j++)
{
isPrime[i*Prime[j]] = 0;
if(i%Prime[j] == 0)
break;
}
}
} int Euler(int p)
{
int ans = p;
for(int i = 0; Prime[i]*Prime[i] <= p ; i++)
{
if( p % Prime[i] == 0)
{
ans = ans - ans/Prime[i];
do
{
p /= Prime[i];
}while(p%Prime[i] == 0);
}
}
if(p > 1)
ans = ans - ans/p;
return ans;
} int main()
{
int p;
make_prime();
while( cin >> p )
{
cout << Euler(p-1) << endl;
}
return 0;
}

  

POJ_1284 Primitive Roots 【原根性质+欧拉函数运用】的更多相关文章

  1. 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}

    题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...

  2. poj 2480 Longge&#39;s problem 积性函数性质+欧拉函数

    题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...

  3. Master of Phi (欧拉函数 + 积性函数的性质 + 狄利克雷卷积)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6265 题目大意:首先T是测试组数,n代表当前这个数的因子的种类,然后接下来的p和q,代表当前这个数的因 ...

  4. 欧拉函数&&欧拉定理

    定义和简单性质 欧拉函数在OI中是个非常重要的东西,不知道的话会吃大亏的. 欧拉函数用希腊字母φ表示,φ(N)表示N的欧拉函数. 对φ(N)的值,我们可以通俗地理解为小于N且与N互质的数的个数(包含1 ...

  5. 欧拉函数(Euler_Function)

    一.基本概述在数论,对正整数n,欧拉函数varphi(n)是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商 ...

  6. POJ1284 Primitive Roots [欧拉函数,原根]

    题目传送门 Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5434   Accepted:  ...

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

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

  8. poj1284(欧拉函数+原根)

    题目链接:https://vjudge.net/problem/POJ-1284 题意:给定奇素数p,求x的个数,x为满足{(xi mod p)|1<=i<=p-1}={1,2,...,p ...

  9. LightOJ1298 One Theorem, One Year(DP + 欧拉函数性质)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1298 Description A number is Almost- ...

随机推荐

  1. Mask_RCNN caffe2

    cd DETECTRON/detectron/ python2 tools/infer_simple_ip_camera.py \    --cfg configs/12_2017_baselines ...

  2. 最新Eclipse Photon安装tomcat

    发现最新版的eclipse竟然没有tomcat配置项,可能是因为spring boot很火,所以server默认就不包含tomcat,需要手动安装组件,  Version: Photon Releas ...

  3. 605. Can Place Flowers零一间隔种花

    [抄题]: Suppose you have a long flowerbed in which some of the plots are planted and some are not. How ...

  4. p5156 [USACO18DEC]Sort It Out

    传送门 分析 我们发现对于没有发现的点相对位置不会发生改变 于是我们可以吧问题转化为求一个lis 于是我们字典序第k小的答案就是字典序第k大的lis 代码 #include<iostream&g ...

  5. File类中的list()和listFiles()方法

    list()方法是返回某个目录下的所有文件和目录的文件名,返回的是String数组 listFiles()方法是返回某个目录下所有文件和目录的绝对路径,返回的是File数组 public class  ...

  6. jQuery对象与DOM对象及互相转化

    <p id=‘’hello”></p> 普通处理,通过标准JavaScript处理: var p = document.getElementById('hello'); p.i ...

  7. 编写高质量代码改善C#程序的157个建议——建议24:迭代器应该是只读的

    建议24:迭代器应该是只读的 如果注意观察会发现,FCL中的迭代器只有GetEnumerator方法,没有SetEnumerator方法,所有的集合类也没有一个可以写的迭代器属性.原因有二: 一:这违 ...

  8. 20169219 实验四Android程序设计

    一.实现Linux下dc的功能,计算后缀表达式的值 public int evaluate(String expr) { int op1, op2, result = 0; String token; ...

  9. 【Android学习】Android编码规范

    四种常见的命名法 比较Java和c#的命名规范的不同点 常量用大写 java方法首字母不大写,应该小写 函数行数限制 不要用拼音 参照物,Android源码 看源码工具,SourceInsight 和 ...

  10. DELPHI XE5 UP2 无真机输出 APP并转换为IPA(实践整理)

    1.在Mac上配置开发环境(具体步骤请百度)   XCODE5.1+IOS7.1SDK+COMMAND LINE TOOLS   安装PlatformAssistant   买一个真机调试账号(实际测 ...