HDU 1164 Eddy's research I(埃拉托斯尼斯筛法求素数)
来源:互联网 发布:网络共享硬盘ip查看 编辑:程序博客网 时间:2024/05/17 07:55
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
素数筛法,第一次用,总感觉我这个筛法有点问题
#include<cstdio>#include<cstring>#include<algorithm>#define N 66000using namespace std;bool isprime[N];int prime[N],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;}
- HDU 1164 Eddy's research I(埃拉托斯尼斯筛法求素数)
- HDU-Eddy's research I-拆分素数
- HDU 1164 Eddy's research I【素数筛选法】
- HDU 1164 Eddy's research I 素数因子
- HDU 1164 Eddy's research I(素数)
- HDU 1164 Eddy's research I(素数连乘)
- hdu 1164 Eddy's research I 打印素数表
- HDU 1164 Eddy's research I
- HDU 1164 Eddy's research I
- hdu 1164 Eddy's research I
- HDU 1164 Eddy's research I
- hdu 1164 Eddy's research I
- Hdu 1164-Eddy's research I
- hdu(1164)Eddy's research I
- HDU 1164 Eddy's research I
- hdu 1164 Eddy's research I
- hdu 1164 Eddy's research I
- HDU 1164 Eddy's research I
- ubuntu 安装 fcitx搜狗输入法
- Java---记录用户名和密码,保存至隐藏文件
- 学习笔记
- 学习历程2016522(1)
- DNS错误
- HDU 1164 Eddy's research I(埃拉托斯尼斯筛法求素数)
- C语言利用openSSL库DES模块加密
- Block
- 学习历程2016522(2)
- [MIT 6.824 Distributed System] Lab 1: MapReduce (2016)
- Android性能优化
- Android线程池及Bitmap加载和Cache
- Android 优化列表卡顿现象的一种办法
- Android的一些综合技术