一、题目

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. c语言实践 1/1+1/2+1/3+1/4+...+1/n

    给定一个n求这个分式的和. int n = 1; float sum = 0; float frac = 0; int i = 1; scanf_s("%d",&n); w ...

  2. Luogu 2704 [NOI2001]炮兵阵地

    唔,想到了状压之后就不会了……实在是菜 考虑压两行,设$f_{i, j, k}$表示当前到第$i$行,上一行是$j$状态,前一行是$k$状态的最多能放的炮兵的数量. 发现第一维还可以滚掉,好像可以转移 ...

  3. Luogu 3616 富金森林公园

    刚看到此题的时候:sb分块??? Rorshach dalao甩手一句看题 于是回去看题……果然是题读错了…… [思路] 对权值离散化后(要先读入所有输入里的权值一起离散化……所以一共有4e4个数据( ...

  4. hdu 2206 IP的计算(最全的注意事项)

    注意: 1.非法字符(包括空格) 如下都是错的 A.145.124.4 192.168.18 123(用scanf输入的话,则接收的是:192.168.18) 2.'.'有且仅有3个,且不能连续出现, ...

  5. jquery数组拼接

    var a=[]; var c=[80,90,70,100] var b={'张三':19,'成绩':c}; a.push(b); console.log("测试案例",a); 同 ...

  6. Android自动提示控件:AutoCompleteTextView和MultiAutoCompleteTextView

    在输入框中输入我们想要输入的信息就会出现其他与其相关的提示信息,这种效果在Android中是用AutoCompleteTextView实现的. 一.AutoCompleteTextView:单一匹配 ...

  7. delphi窗体启动外部exe

    uses Winapi.Windows; WinExec(PAnsiChar(Application.ExeName), sw_normal);   // PAnsiChar : string to ...

  8. React+gulp+browserify模块化开发

    阅读本文需要有React的基础知识,可以在React 入门实例教程和React中文官网进行基础学习. 没有React基础也可以学习本文,本文主要不是学习React,而是gulp+browserify进 ...

  9. DOM--sql server

    public List<LianHeData> select(int ID) { List<LianHeData> list = new List<LianHeData& ...

  10. angular resolve路由

    import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from "@angular/router&q ...