Primitive Roots
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4775   Accepted: 2827

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

Source

题目大意:求n的原根个数.
分析:结论题,n的原根个数=φ(φ(n)).
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,phi[],prime[],tot,vis[]; void init()
{
phi[] = ;
for (int i = ; i <= ; i++)
{
if (!vis[i])
{
prime[++tot] = i;
phi[i] = i - ;
}
for (int j = ; j <= tot; j++)
{
int t = prime[j] * i;
if (t > )
break;
vis[t] = ;
if (i % prime[j] == )
{
phi[t] = phi[i] * prime[j];
break;
}
phi[t] = phi[i] * (prime[j] - );
}
}
} int main()
{
init();
while (scanf("%d",&n) != EOF)
printf("%d\n",phi[n - ]); }

poj1284 Primitive Roots的更多相关文章

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

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

  2. [POJ1284]Primitive Roots(原根性质的应用)

    题目:http://poj.org/problem?id=1284 题意:就是求一个奇素数有多少个原根 分析: 使得方程a^x=1(mod m)成立的最小正整数x是φ(m),则称a是m的一个原根 然后 ...

  3. POJ1284 Primitive Roots (原根)

    题目链接:http://poj.org/problem?id=1284 题目描述: 题目大意: 一个质数原根的个数 题解: 结论题 一个数n的原根的个数等于$\varphi(\varphi(n))$ ...

  4. Primitive Roots(poj1284)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3928   Accepted: 2342 D ...

  5. 【HDU 4992】 Primitive Roots (原根)

    Primitive Roots   Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...

  6. POJ 1284 Primitive Roots 原根

    题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...

  7. POJ 1284:Primitive Roots(素数原根的个数)

    Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5709 Accepted: 3261 Descr ...

  8. POJ 1284 Primitive Roots 数论原根。

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2479   Accepted: 1385 D ...

  9. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

随机推荐

  1. 【转】PHPCMS+PHPExcel实现后台数据导入导出功能

    首先,上图之中的红色框框是没有的,我们想要给他加上,当然是要改HTML页面啦,废话,我们跟ECSHOP一样由PHP路径找模板: 看看路由原理: 首先,上图之中的红色框框是没有的,我们想要给他加上,当然 ...

  2. hdu - 6276,2018CCPC湖南全国邀请赛A题,水题,二分

    题意: 求H的最大值,  H是指存在H篇论文,这H篇被引用的次数都大于等于H次. 思路:题意得,  最多只有N遍论文,所以H的最大值为N, 常识得知H的最小值为0. 所以H的答案在[0,N]之间,二分 ...

  3. Rest-Assured 测试框架

    Rest-Assured 是一个测试 Restful Web Service 的 Java 类库,我们能够测试各种各样的请求组合,依次测试核心业务逻辑的不同组合. 它是通过发送特定的rest api, ...

  4. RC电路简介,RC串并联电路的工作原理及应用

    RC电路简介,RC串并联电路的工作原理及应用 RC电路全称Resistance-Capacitance Circuits.一个 相移电路(RC电路)或称 RC滤波器. RC网络, 是一个包含利用电压源 ...

  5. redis与mysql性能对比、redis缓存穿透、缓存雪崩

    写在开始 redis是一个基于内存hash结构的缓存型db.其优势在于速读写能力碾压mysql.由于其为基于内存的db所以存储数据量是受限的. redis性能 redis读写性能测试redis官网测试 ...

  6. 清空git缓存

    git rm -r --cached .git add . git commit -m 'update .gitignore' 读了下git文档,才发现,这些东西其实很简单,很容易理解.cached其 ...

  7. WEB前端开发流程总结

    作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正 WEB前端开发项目流程总结 1.新建项目 ...

  8. 20135208JAVA第二次试验

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计  班级:1352 姓名:贺邦  学号:20135208 成绩:             指导教师:娄嘉鹏  ...

  9. 读 《我是一只IT小小鸟》 有感

    在没有上大学之前,我很迷茫自己将来要从事什么行业.有人说,人生的每一个阶段都应该有自己的目标,然而,我上大学之前,甚至大一下学期之前,我对于我今后的从业道路,人生规划,都是迷茫的.高考结束成绩出来后, ...

  10. beta阶段评语

    首先我说一下自己心中的排序 1.俄罗斯方块 2 连连看 3 考试管理系统 4 食物链教学软件 5 约跑App 6 礼物挑选小工具 我的理由: 新峰的俄罗斯的方块,虽然当初的亮点没做出来,但是整体流程完 ...