POJ-2739 Sum of Consecutive Prime Numbers
来源:互联网 发布:张国荣 知乎 编辑:程序博客网 时间:2024/06/03 15:31
#include <iostream>#include <stdio.h>using namespace std;int main(){ int n; int a[10000]; int k = 0; for(int m = 2;m <= 10000;m++) { int t = 1; for(int i = 2;i*i <= m;i ++) { if (m % i == 0) { t = 0; break; } } if(t) { a[k] = m; k ++; } } while(scanf("%d",&n)!=EOF&&n) { int x = 0; for(int i=0;a[i]<=n;i++) { int sum=0; for(int j=i;a[j]<=n;j++) { sum+=a[j]; if(sum==n) { x++; break; } else if(sum>n) break; } } printf("%d\n",x); } return 0;}
/*应该算是水题 枚举10000以内的素数存入数组再进行sum筛选。一开始把sum位置放错导致错误。*/
0 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
- 《SICP•2.1 数据抽象简介》
- boost Data & Time 笔记
- codeblocks快捷键(转载)
- iis站点获取时间日期问题
- foobar 解决dts和sacd的问题
- POJ-2739 Sum of Consecutive Prime Numbers
- JDBC
- 保存的博客(更新中。。。。。)
- 3117 高精度练习之乘法
- git学习历程
- Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOv
- 1045 access denied for user 'root'@'localhost' using password yes
- struts中action名称重复导致的奇异事件
- 64位Linux系统编译32位汇编程序