POJ1284 Primitive Roots [欧拉函数,原根]
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 5434 | Accepted: 3072 |
Description
Write a program which given any odd prime 3 <= p < 65536 outputs the number of primitive roots modulo p.
Input
Output
Sample Input
23
31
79
Sample Output
10
8
24
分析:
一句话题意:求原根的个数。
首先,如果知道原根的相关知识,那就可以直接上欧拉函数的板子了。关于原根的知识,请参考这里。
Code:
//It is made by HolseLee on 11th July 2018
//POJ 1284
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<iomanip>
using namespace std;
const int N=1e5+;
int n,phi[N],top,q[];
bool vis[N];
void ready()
{
phi[]=;
for(int i=;i<N;i++){
if(!vis[i])phi[q[++top]=i]=i-;
for(int j=,k;j<=top&&(k=i*q[j])<N;j++){
vis[k]=true;
if(i%q[j])phi[k]=phi[i]*(q[j]-);
else {phi[k]=phi[i]*q[j];break;}
}
}
}
int main()
{
ios::sync_with_stdio(false);
ready();
while(cin>>n){
printf("%d\n",phi[n-]);}
return ;
}
POJ1284 Primitive Roots [欧拉函数,原根]的更多相关文章
- POJ 1284 Primitive Roots (欧拉函数+原根)
<题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...
- 【POJ1284】Primitive Roots 欧拉函数
题目描述: 题意: 定义原根:对于一个整数x,0<x<p,是一个mod p下的原根,当且仅当集合{ (xi mod p) | 1 <= i <= p-1 } 等于{ 1, .. ...
- poj1284(欧拉函数+原根)
题目链接:https://vjudge.net/problem/POJ-1284 题意:给定奇素数p,求x的个数,x为满足{(xi mod p)|1<=i<=p-1}={1,2,...,p ...
- poj1284:欧拉函数+原根
何为原根?由费马小定理可知 如果a于p互质 则有a^(p-1)≡1(mod p)对于任意的a是不是一定要到p-1次幂才会出现上述情况呢?显然不是,当第一次出现a^k≡1(mod p)时, 记为ep(a ...
- poj1284 && caioj 1159 欧拉函数1:原根
这道题不知道这个定理很难做出来. 除非暴力找规律. 我原本找的时候出了问题 暴力找出的从13及以上的答案就有问题了 因为13的12次方会溢出 那么该怎么做? 快速幂派上用场. 把前几个素数的答案找出来 ...
- 数学之欧拉函数 &几道poj欧拉题
欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include<iostream> #include<cstdio> #include<cstring> ...
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
随机推荐
- Drools规则引擎环境搭建
Drools 是一款基于Java 的开源规则引擎,所以在使用Drools 之前需要在开发机器上安装好JDK 环境,Drools5 要求的JDK 版本要在1.5 或以上. Drools5 提供了一个基于 ...
- [LeetCode] 25. Reverse Nodes in k-Group ☆☆☆
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k ...
- Python学习笔记(三十三)常用内置模块(2)collections_namedtuple_deque_defaultdict_OrderedDict_Counter
摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431953239 ...
- 更改gradle的java的class文件输出目录的结构
group 'com.thinkvenus.common'version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 r ...
- 【BZOJ】1426: 收集邮票 期望DP
[题意]有n种不同的邮票,第i次可以花i元等概率购买到一种邮票,求集齐n种邮票的期望代价.n<=10^4. [算法]期望DP [题解]首先设g[i]表示已拥有i张邮票集齐的期望购买次数,根据全期 ...
- POJ - 1330 Nearest Common Ancestors 最近公共祖先+链式前向星 模板题
A rooted tree is a well-known data structure in computer science and engineering. An example is show ...
- 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...
- VS 2010 应用程序无法启动
其实一般遇到这种问题, 不管是debug还是release, 也不用看提示的内存地址, 首先应该想到库是否包含正确. 一个可能的错误就是32位或64位不匹配的错误. 比如环境变量设的是64位的Open ...
- 【IDEA】IDEA中maven项目pom.xml依赖不生效解决
问题: 今天在web项目中需要引入poi相关jar包.查看之下才发现pom.xml中的依赖虽然已经下载到了本地仓库 repository,但是却没有加入到项目路径的 Extenal Libraries ...
- Linux CGI编程基础【整理】
Linux CGI编程基础 1.为什么使用CGI? 如前面所见,任何的HTML均是静态网页,它无法实现一些复杂的功能,而CGI可以为我们实现.如:a.列出服务器上某个目录中的文件,对目录中的文件进行操 ...