poj 2739 Sum of Consecutive Prime Numbers
2013-04-04 14:42
323 查看
#include<cstdio> #include<iostream> #include<stdlib.h> #include<ctype.h> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<iomanip> #include<set> #include<string> #include<iterator> #define maxn 100000 using namespace std; int p[maxn]; int q[maxn]; int ans; int sn; void prime(){ p[0]=p[1]=0; sn=0; for(int i=2;i<maxn;i++) p[i]=1; for(int i=2;i<maxn;i++) if(p[i]){ q[sn++]=i; for(int j=i+i;j<maxn;j+=i) p[j]=0; } } void work(int n,int k){ if(k<0) return; if(n-q[k]==0){ ans++; } else if(n-q[k]>0){ work(n-q[k],k-1); } else return; return ; } int main(){ int n; while(cin>>n,n){ prime(); ans=0; int k; for(int i=0;i<1330;i++) if(n==q[i]){ k=i-1; ans++; break; } else if(n<q[i]){ k=i-1; break; } for(int i=k;i>=0;i--) work(n,i); cout<<ans<<endl; } }
相关文章推荐
- 【原】 POJ 2739 Sum of Consecutive Prime Numbers 筛素数+积累数组 解题报告
- poj2739 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
- LA-3399 & 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( *【素数存表】+暴力枚举 )