UVa1210 - Sum of Consecutive Prime Numbers
来源:互联网 发布:图片尺寸测量标注软件 编辑:程序博客网 时间:2024/06/07 02:47
#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;}
0 0
- UVa1210 Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers(欧拉筛法即线性筛法)
- UVALive3399 UVA1210 POJ2739 Sum of Consecutive Prime Numbers【素数筛选+尺取法】
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers pku 2739
- POJ2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- Android开发计算器之布局
- 黑马程序员——面向对象基础(一)
- 浅谈设计模式:工厂模式(Factory Pattern)
- leetcode word break 2
- 根据年月日推算是星期几的公式
- UVa1210 - Sum of Consecutive Prime Numbers
- 【Unity】NGUI插件核心脚本类的继承关系
- EFI分区win7、Ubuntu 12 desktop 64位双系统引导设置
- Oracle存储过程简例1
- 【LeetCode】Flatten Binary Tree to Linked List
- 计算某一天是当年的第几天——菜鸟学编程1
- Android:在ADT中快速多行注释的方法
- leetcode search for a range
- Thread笔记