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. 2.1 Oracle之DML的SQL语句之单表查询以及函数

    1.SQL简介 对于不同的数据库来说,SQL语句是相通的,关系型数据库都以SQL语句为操作的标准,只是相应的数据库对应的函数不相同. SQL(Structured Query Language,结构化 ...

  2. Redis5.0:现公测全免费,点击就送,注册账号,即开即用

    华为云分布式缓存服务Redis,是华为云服务的一款核心产品. 分布式缓存Redis是一款内存数据库服务,基于双机热备的高可用架构,提供单机.主从.集群等丰富类型的缓存类型. 现推出最新版本Redis5 ...

  3. LCA(Tarjan算法)模板

    一.查询一组的LCA Nearest Common Ancestors A rooted tree is a well-known data structure in computer science ...

  4. Scrum立会报告+燃尽图(Beta阶段第一次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://coding.net/u/wuyy694 ...

  5. 周总结<7>

    这周和3位朋友一起完成了系运动会的视频,感受很多,也学到很多. 周次 学习时间 新编代码行数 博客量 学到知识点 14 20 100 1 Html页面设计:虚拟机:(C语言)最小生成树与最短路径 Ht ...

  6. IHttpModule的那些事

    写在前面 关于IHttpModule的相关内容,在面试的时候也被问到过,当时也是隐隐约约的感觉这个接口有一个Init方法,可以在实现类中的Init方法注册一系列的事件,说句实话,具体哪些事件,忘了差不 ...

  7. Notepad++如何多视图(分屏)显示

    Notepad++ v6.6.7 当需要同时查阅或者编辑多个文件时,正是多视图功能大显身手的时候. 可以在你想要在另一边预览操作的文件名字(在工具栏和文件内容之间)上,单击右键,如下图所示,选择移动到 ...

  8. Spring管理过滤器:org.springframework.web.filter.DelegatingFilterProxy

    配置web.xml <filter>        <filter-name>springSecurityFilterChain</filter-name>     ...

  9. JavaWeb应用的生命周期

    JavaWeb应用的生命周期是由Servlet容器来控制. 启动阶段 (1)读取web.xml配置文件数据 (2)为JavaWeb应用创建一个ServletContext对象 (3)对所有的Filte ...

  10. Week2-作业1 -阅读《构建之法》

    第一章 在阅读第1.2.2节时,感受最深,记得开学初有老师就给我们分析过计算机专业和我们专业的区别,当时是给我们讲的是计算机科学注重的是理论,偏向于硬件方面,而软件工程则注重实践,偏向于软件方面.然很 ...