Primitive Roots
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3381   Accepted: 1980

Description

We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (xi 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

一个数m的1次方,2次方,3次方到n-1次方 mod n 得到的数值各不相同,就说m是n的原根。

一个数是数n的原根就必然与n-1互质,所以求n的原根的数量即是求欧拉函数n-1。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; long long euler(long long n)
{
long long res = n, a = n;
for (long long i = 2; i*i <= a; i++)
{
if (a%i == 0)
{
res = res / i*(i - 1);
while (a%i == 0)a /= i;
}
}
if (a > 1)res = res / a*(a - 1);
return res;
} int main()
{
long long n;
while (cin >> n)
{
cout << euler(n-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. POJ 1284 Primitive Roots (欧拉函数+原根)

    <题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...

  7. poj 1284 Primitive Roots(未完)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3155   Accepted: 1817 D ...

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

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

  9. poj 1284 Primitive Roots

    从来没有接触过完全剩余系,不会证明,知道看了别人的题解才知道要用欧拉函数: 下面是证明过程: p是奇素数,如果{xi%p | 1 <= i <= p - 1} = {1,2,...,p-1 ...

随机推荐

  1. oracle练习-day01

    .基础查询 yearly .条件查询小于的员工 ; ;的员工;  ,,); .模糊查询.排序.字符函数,) test .数值函数.,),round(.,),round(.) .,.),trunc(., ...

  2. 「Luogu1402」酒店之王

    传送门 Luogu 解题思路 网络流板子题. 建图细节见代码,也可以参考这道差不多的题 细节注意事项 咕咕咕. 参考代码 #include <algorithm> #include < ...

  3. C语言学习从入门到精通书籍,10万读者都认可

    C语言程序设计从入门到精通 10万读者认可的编程图书精粹 零基础自学编程的入门图书 详解C语言编程思想和核心技术 很多初学者,对C语言.c++的概念都是模糊不清的,C语言.c++是什么,能做什么,学的 ...

  4. redis提供的持久化机制(rdb,aof)

    Redis提供的持久化机制 Redis是一种面向“key-value”类型数据的分布式NoSQL数据库系统,具有高性能.持久存储.适应高并发应用场景等优势.它虽然起步较晚,但发展却十分迅速. 近日,R ...

  5. 连续(Continuity) - 有界(Bounded) - 收敛(Convergence)

    连续(Continuity) 所有点连续   ->   一致连续 (uniform continuity)  ->  绝对连续  -> 李普希兹连续(Lipschitz) 弱    ...

  6. 关于目标检测的anchor问题

    关于目标检测其实我一直也在想下面的两个论断: Receptive Field Is Natural Anchor Receptive Field Is All You Need 只是一直没有实验.但是 ...

  7. dubbo-admin的安装使用

    dubbo-admin下载地址:https://github.com/apache/incubator-dubbo/releases 可以直接下载到linux上 wget https://github ...

  8. Docker 学习之镜像导入导出及推送阿里云服务器(三)

    在前面两节里主要就是记录一些docker的基本的操作,包括搜索镜像,拉取镜像,根据镜像创建容器等等,在这一节主要就是记录Docker对于镜像文件的导入导出,及推送到阿里云再从阿里云获取镜像. 一.镜像 ...

  9. 安装数据库Typical path for xclock: /usr/X11R6/bin/xclock 错误问题

    [oracle@localhost database]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp spa ...

  10. MySQL 批量更新、删除数据shell脚本

    #!/bin/bash. ~/.bash_profilelog=/tmp/update_log_1_$(date +%F).logvstart=1step=100vstop=$((${vstart}+ ...