POJ 2739 Sum of Consecutive Prime Numbers
来源:互联网 发布:大麦盒子看电视软件 编辑:程序博客网 时间:2024/06/03 16:33
又是一道质数的题……
题意:将一个正整数写成连续质数的和,输出有几种写法。
依然筛法,不同的是建了个数组存储质数,不然后面判断麻烦。
第一次提交时RE,感觉不会数组不会越界啊……还是把29行改成了i<n/2 顺利AC
//尽快刷完水题我要开始学算法了啊擦!
#include<stdio.h>_Bool prime[10000];int num[5000];int findprime(){int i,j,k=0; prime[0] = 0; prime[1] = 0;for(i=2;i<10000;i++) prime[i]=1; for (i=2; i<10000; i++) if (prime[i]) { num[k++]=i; for (j=i+i; j<10000; j+=i) prime[j] = 0; }}int main(){int n,i,j,m,sum;findprime();while(scanf("%d",&n) && n!=0){m=0;for(i=0;i<=n/2;i++){for(j=i,sum=0;sum<n;j++)sum+=num[j];if(sum==n)m++;}printf("%d\n",m);}return 0;}
- POJ 2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- POJ-2739-Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- poj - 2739 - Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- 【POJ-2739】Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- POJ-2739-Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- Java 调用 Shell 命令
- 找到一款不错的网站压力测试工具webbench
- Android模拟器 卸载apk文件
- myeclipse中java注释乱码的解决
- Ubuntu将man文档改为中文
- POJ 2739 Sum of Consecutive Prime Numbers
- python (paramiko模块) 利用id_rsa登陆远程的服务器
- 基于Java容器类的线程安全编程
- DPL,RPL,CPL 之间的联系和区别
- Windows和Linux编译Live555的Debug版本(可调式)
- ruby rails的好博客
- android按钮点击时间倒数
- 函数式编程扫盲篇
- ruby rails 的复制 dup clone