UVa1210 - Sum of Consecutive Prime Numbers
2015-03-28 23:55
387 查看
#include<cstdio> const int maxn=10010; int isp[1250],pre_p,sum[1250]; bool np[maxn]={true,true}; void prepare(){ for(int i=2;i<maxn;++i){ if(!np[i]) isp[pre_p++]=i; for(int j=0;j<pre_p&&i*isp[j]<maxn;++j) { np[i*isp[j]]=true; if(!(i%isp[j])) break; } } for(int i=1;i<=pre_p;i++){ sum[i]=sum[i-1]+isp[i-1]; } return; } int main() { prepare(); int n; while(~scanf("%d",&n)&&n){ int cnt = 0; for(int i=0;i<pre_p;++i){ if(isp[i]>n) break; for(int j=i+1;j<=pre_p;++j) if(n==sum[j]-sum[i]) ++cnt; } printf("%d\n",cnt); } return 0; }
相关文章推荐
- UVA 1210 Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers(素数打表)
- UVa1210 Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers(数论)
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVALive3399 UVA1210 POJ2739 Sum of Consecutive Prime Numbers【素数筛选+尺取法】
- UVa 1210 - Sum of Consecutive Prime Numbers(素数+连续和)
- Sum of Consecutive Prime Numbers - UVa 1210 水题
- 习题10-6 UVA - 1210 Sum of Consecutive Prime Numbers 连续素数之和(滑动窗口)
- 【UVA】1210 - Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers UVA - 1210 连续素数之和
- Sum of Consecutive Prime Numbers UVA - 1210
- UVA - 1210 - Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers(欧拉筛法即线性筛法)
- [UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)
- UVa 1210 - Sum of Consecutive Prime Numbers(滑动窗口)
- UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
- Uva-1210 Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers