一、题目

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. linux上mysql安装

    所有平台的MySQL下载地址为: MySQL 下载. 挑选你需要的 MySQL Community Server 版本及对应的平台. MySQL - MySQL服务器.你需要该选项,除非你只想连接运行 ...

  2. 【转】LVS负载均衡之session解决方案 持久连接

    原文地址:http://minux.blog.51cto.com/8994862/1744761 1. 持久连接是什么? 1.1 在LVS中,持久连接是为了用来保证当来自同一个用户的请求时能够定位到同 ...

  3. mybatis的执行流程 #{}和${} Mysql自增主键返回 resultMap 一对多 多对一配置

    n Mybatis配置 全局配置文件SqlMapConfig.xml,配置了Mybatis的运行环境等信息. Mapper.xml文件即Sql映射文件,文件中配置了操作数据库的Sql语句.此文件需要在 ...

  4. boost库中sleep方法详解

    博客转载自:https://blog.csdn.net/huang_xw/article/details/8453506 boost库中sleep有两个方法: 1. 这个方法只能在线程中用, 在主线程 ...

  5. easyui-tabs 页签绑定click事件,动态加载jqgrid

    .前台代码 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" ...

  6. sed 之 & 符号

    sed 之 & 符号 摘自:https://blog.csdn.net/jasonliujintao/article/details/53509620 & 这个符号,其实很有用,在对相 ...

  7. EasyUI combobox实现下拉框多选遇坑记录

    场景一: 多选正常从第二个选项增加逗号,我选第一个的时候就冒出一个逗号 解决方案一: 这是因为当前的下拉框的值可能为undefined,需要手动清空一下 $("#id").comb ...

  8. 一个Sql备注

    ;WITH CTE AS ( SELECT [RGTCID] ,ltrim(rtrim(T.N.value('.','varchar(100)'))) as Querystr FROM [R_GT_C ...

  9. 一个数组:1,1,2,3,5,8,13,21...+m,求第30位数是多少?用递归实现;(常考!!!)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  10. Unity3D管网分析

    给大家分享一下自己之前没事写的Unity3D的插件,主要用来对管网的搭建和分析, 开源在Github上 https://github.com/LizhuWeng/PipeNet,可以给需要的朋友做一个 ...