poj 1284——Primitive Roots
来源:互联网 发布:打电话自动录音软件 编辑:程序博客网 时间:2024/05/17 03:52
题意:求65536以内的素数的原根个数
思路:素数的原根个数就是phi(p-1)。
错误:没有注意到题目中说了是素数,就从1到p一个一个试原根,导致超时
代码如下:
#include<cstdio>#include<iostream>#include<cstring>#include<vector>using namespace std;const int maxn=70000;int minDiv[maxn],phi[maxn],sum[maxn];void genPhi(){ for(int i=1;i<maxn;++i) { minDiv[i]=i; } for(int i=2;i*i<maxn;++i) { if(minDiv[i]==i){ for(int j=i*i;j<maxn;j+=i) { minDiv[j]=i; } } } phi[1]=1; for(int i=2;i<maxn;++i){ phi[i]=phi[i/minDiv[i]]; if((i/minDiv[i])%minDiv[i]==0) { phi[i]*=minDiv[i]; } else{ phi[i]*=(minDiv[i]-1); } }}int main(){ // freopen("data.txt","r",stdin); genPhi(); int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",phi[n-1]); } return 0;}
0 0
- poj 1284——Primitive Roots
- POJ 1284 Primitive Roots
- poj - 1284 - Primitive Roots
- Poj 1284 Primitive Roots
- 【POJ 1284】Primitive Roots
- POJ 1284 primitive roots
- POJ 1284Primitive Roots
- POJ 1284 Primitive Roots
- poj 1284 Primitive Roots
- POJ-1284-Primitive Roots
- POJ 1284 Primitive Roots(素数原根)
- POJ 1284 Primitive Roots (求原根个数)
- poj 1284 Primitive Roots 【原根】【数论】
- POJ 1284 Primitive Roots 原根
- POJ-1284-Primitive Roots 解题报告
- poj 1284 Primitive Roots 求素数元根数
- POJ 1284 Primitive Roots (原根)
- POJ 1284 Primitive Roots(欧拉函数)
- The number of steps - UPC 2225 dp
- python发送、解析邮件
- 一款功能强大齐全的PDF转换软件
- cell和lable自适应高度
- 20140705
- poj 1284——Primitive Roots
- python 创建子进程subprocess以及注意的问题(死锁)
- 下载百度网盘已经失效的资源链接
- 商城二次开发-----20140705
- 一个小错误 要注意org.dom4j.DocumentException
- 火狐中无法打开google的搜索结果的解决方式
- IOS-Xcode5.1.1创建Xib工程
- UVa 10125 - Sumsets
- 读书笔记1——Apriori算法详解