【POJ1284】Primitive Roots
【题目大意】
给你一个素数n,求n的原根个数。
【题解】
关于原根有一个定理:
定理:如果模有原根,那么它一共有
个原根。
所以这题就是求phi[phi[n]]
很简单吧。。。(如果知道这个定理的话)
/**************
POJ 1284
by chty
2016.11.10
**************/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
#define FILE "read"
#define MAXN 70010
int n,cnt,prime[MAXN],isprime[MAXN],phi[MAXN];
inline int read()
{
int x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
void get()
{
phi[]=;
for(int i=;i<=;i++)
{
if(!isprime[i]) prime[++cnt]=i,phi[i]=i-;
for(int j=;j<=cnt&&prime[j]*i<=;j++)
{
isprime[prime[j]*i]=;
if(i%prime[j]==) {phi[prime[j]*i]=phi[i]*prime[j];break;}
else phi[prime[j]*i]=phi[i]*(prime[j]-);
}
}
}
int main()
{
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
get();
while(~scanf("%d",&n)) printf("%d\n",phi[phi[n]]);
return ;
}
【POJ1284】Primitive Roots的更多相关文章
- 【POJ1284】Primitive Roots 欧拉函数
题目描述: 题意: 定义原根:对于一个整数x,0<x<p,是一个mod p下的原根,当且仅当集合{ (xi mod p) | 1 <= i <= p-1 } 等于{ 1, .. ...
- 【HDU 4992】 Primitive Roots (原根)
Primitive Roots Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...
- 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}
题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...
- POJ1284:Primitive Roots——题解
http://poj.org/problem?id=1284 给一个奇质数p,求p的原根数量. 有一个结论:当正整数n存在原根时,其一共有phi(phi(n))个不同余的原根. 所以答案为phi(p- ...
- POJ_1284 Primitive Roots 【原根性质+欧拉函数运用】
一.题目 We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if t ...
- poj1284 Primitive Roots
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4775 Accepted: 2827 D ...
- POJ1284 Primitive Roots [欧拉函数,原根]
题目传送门 Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5434 Accepted: ...
- Primitive Roots(poj1284)
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3928 Accepted: 2342 D ...
- Primitive Primes - 题解【数学】
题面 It is Professor R's last class of his teaching career. Every time Professor R taught a class, he ...
随机推荐
- 使用service&scope 进行注入
@service 声明该类为一个bean,bean的名称为类名首字母小写(customerService) @Scope("prototype")则声明为一个原子类型,既每个get ...
- javascript把json串转成对象
// 这个是待转的json串 var jstr = "{'a':100,'b':'aaa'}"; // 经过下面语句把这个语句描述的对象数据,赋给这个m对象了 eval (&quo ...
- 几个中文排版web 类库
1. typo.css http://typo.sofi.sh/ 2. yue.css http://lab.lepture.com/yue.css/ 规范,统一才是开发的王道.
- Adreno Profiler 提取手机游戏资源
https://blog.csdn.net/lly20000/article/details/79774755 step.1 准备工具 1.adb连接工具(我用的cofface adb ) [cof ...
- webstorm配置scss的小结
1)安装ruby 2)安装sass 3)配置webstorm 打开webstrom ->file->setting->Tools->file watcher 添加scss pr ...
- CArray,CList,CMap如何实例化
1.定义一个CMap,向这个CMap中增加数据项(键-值对).CMap<CString, LPCTSTR, CString, LPCTSTR>m_ItemMap;CString strKe ...
- Jquery each循环中中断
在each代码块内不能使用break和continue,要实现break和continue的功能的话,要使用其它的方式 break----用return false; continue --用retu ...
- 阻塞队列之三:SynchronousQueue同步队列 阻塞算法的3种实现
一.SynchronousQueue简介 Java 6的并发编程包中的SynchronousQueue是一个没有数据缓冲的BlockingQueue,生产者线程对其的插入操作put必须等待消费者的移除 ...
- 列表:list[1],切片list[1:3],追加insert,修改,删除remove,del,pop,查找index,统计count,清空list.clear() 翻转list.reverse(),排序list.sort(),扩展list.extend,
列表的定义: 列表的使用以及取值:用逗号的方式,取列表两个值,会打印出2个项目,两个项目之间自动有一个空格. 如果想取中间几个值: 请注意,如果取值1和2,那么要写[1,3],要记住这里是顾头不顾尾. ...
- 【洛谷】P1388 算式(dp)
题目描述 给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号.例如: N ...