poj 2739 Sum of Consecutive Prime Numbers
2014-08-16 15:11
288 查看
题目大意:
给你一个数,让你判断有几组连续的素数之和与其相等。
此题比较水。。。
给你一个数,让你判断有几组连续的素数之和与其相等。
此题比较水。。。
#include<stdio.h> #include<string.h> bool f[10000];//标记数组 int a[5000]; int cont; void ss() { int i,j; cont=0; memset(f,true,sizeof(f)); for(i=2;i<10000;i++)//筛选素数 { if(f[i])//标记,用于判断是否为素数 { a[cont++]=i; for(j=i*i;j<10000;j+=i) { f[j]=false; } } } } int main() { int i,n,count,t,s; ss(); while(~scanf("%d",&n)) { if(n==0) break; if(n==1)//对特殊情况1进行处理 { printf("0\n"); continue; } count=0; for(i=0;i<cont;i++) { t=i; s=0; while(s<n) { s=s+a[t]; t++; } if(s==n) count++;//记录相等的组数 } printf("%d\n",count); } 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
- POJ2739 - Sum of Consecutive Prime Numbers(素数问题)
- Sum of Consecutive Prime Numbers--POJ 2739
- 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