一、题目

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. Java “hello word” 第一天

    //新建包和类 //java是包,c#是命名空间package test1;/** * 需求:练习一个hello word * 思路: * 1.定义一个类,因为java程序都是以类的形式存在的,类的形 ...

  2. php扩展开发3--扩展类传参数

    1.需要实现的细节 实现一个person类 ,实现一个doing方法和saying方法 在构造方法中传递一个数组,在doing中打印此数组 saying方法中,构建一个空数组,返回,不需要传参. 2. ...

  3. 408. Valid Word Abbreviation有效的单词缩写

    [抄题]: Given a non-empty string s and an abbreviation abbr, return whether the string matches with th ...

  4. js 禁止后退键

    function doKey(e) { var ev = e || window.event; //获取event对象 var obj = ev.target || ev.srcElement; // ...

  5. HDU 3365 New Ground (计算几何)

    题意:给定点A[0~n-1]和B[0],B[1],A[0].A[1]映射到B[0].B[1],求出其余点的映射B[2]~B[n-1]. 析:运用复数类,关键是用模板复数类,一直编译不过,我明明能编译过 ...

  6. Unity破解不成功解决方案

    你是不是遇到过Unity新版本出来的时候就急着使用,但是安装好了,却破解不成功的问题(你之前的版本破解过).这是由于你的注册表没有彻底的删除,接下来我们图解如何清理. 1.卸载以前的版本,卸载完了删除 ...

  7. Highway Networks(高速路神经网络)

    Rupesh Kumar Srivastava (邮箱:RUPESH@IDSIA.CH)Klaus Greff (邮箱:KLAUS@IDSIA.CH)J¨ urgen Schmidhuber (邮箱: ...

  8. POJ3233 Matrix Power Series(矩阵快速幂+分治)

    Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. ...

  9. 做ETL的时候用到的数据同步更新代码

    这里是用的从一个库同步到另一个库,代码如下 private void IncrementalSyncUpdate(string fromConn, string toConn, Dictionary& ...

  10. C# LINQ(3)

    我们还是接着讨论一下group by 这一章节讨论group的本质:分组. 分组之后进行存储或者查询. 这个时候就要用一个新的关键字:into 这个之后就group就不作为结尾了. 必须重写另起sel ...