HDU 1164 Eddy's research I(埃拉托斯尼斯筛法求素数)
2016-05-23 07:53
423 查看
Eddy’s research I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8531 Accepted Submission(s): 5242
Problem Description
Eddy’s interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can’t write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .
Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.
Output
You have to print a line in the output for each entry with the answer to the previous question.
Sample Input
11
9412
Sample Output
11
2*2*13*181
素数筛法,第一次用,总感觉我这个筛法有点问题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8531 Accepted Submission(s): 5242
Problem Description
Eddy’s interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can’t write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .
Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.
Output
You have to print a line in the output for each entry with the answer to the previous question.
Sample Input
11
9412
Sample Output
11
2*2*13*181
素数筛法,第一次用,总感觉我这个筛法有点问题
#include<cstdio> #include<cstring> #include<algorithm> #define N 66000 using namespace std; bool isprime ; int prime ,nprime; void doprime() { int i,j; nprime=0; memset(isprime,true,sizeof(isprime)); isprime[1]=0; for(i=2;i<N;i++) { if(isprime[i]) { prime[++nprime]=i; for(int j=2*i;j<N;j+=i) { isprime[j]=false; } } } } int main() { doprime(); int n; while(~scanf("%d",&n)) { int flag=0; for(int i=1;i<=nprime;i++) { if(n%prime[i]==0) { while(n) { n=n/prime[i]; if(n==1) { printf("%d",prime[i]); flag=1; break; } else { printf("%d*",prime[i]); } if(n%prime[i]!=0) { break; } } } if(flag==1) { break; } } printf("\n"); } return 0; }
相关文章推荐
- 出差(3~十二)
- 学习笔记
- 学习历程2016522(1)
- DNS错误
- slitaz的使用笔记
- Java---记录用户名和密码,保存至隐藏文件
- ubuntu 安装 fcitx搜狗输入法
- shiro salt
- shiro salt
- 【BZOJ2733】[HNOI2012]永无乡【启发式合并】【Splay】
- UI基础第三天(代码)
- angularjs事件指令--ngClick、ngDbclick、ngCut、ngChange、ngKeydown...
- 微博,微信图片浏览过渡动画的实现
- 云计算相关论文目录
- Redis3 本地安装集群的记录
- 结合Jexus + Kestrel 部署 asp.net core 生产环境
- 除了技术,我们还能拼什么?
- x
- redis连接数
- 简单的函数指针介绍