https://vjudge.net/problem/UVA-1210

统计质数前缀和,枚举左右端点,这一段的区间和+1

#include<cstdio>
#define N 10001
using namespace std;
int cnt,p[N],sum[N],ans[N];
bool v[N];
int main()
{
for(int i=;i<N;i++)
{
if(!v[i])
{
v[i]=true;
p[++cnt]=i;
}
for(int j=;j<=cnt;j++)
{
if(i*p[j]>=N) break;
v[i*p[j]]=true;
if(i%p[j]==) break;
}
}
for(int i=;i<=cnt;++i) sum[i]=sum[i-]+p[i];
for(int r=;r<=cnt;r++)
for(int l=r;l;l--)
{
if(sum[r]-sum[l-]>=N) break;
ans[sum[r]-sum[l-]]++;
}
int n;
while(scanf("%d",&n)!=EOF)
{
if(!n) return ;
printf("%d\n",ans[n]);
}
}

UVA 1210 Sum of Consecutive Prime Numbers的更多相关文章

  1. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  2. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  3. POJ2739 Sum of Consecutive Prime Numbers(尺取法)

    POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...

  4. POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25225 ...

  5. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS   Memory Limit: 6 ...

  6. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

  7. POJ.2739 Sum of Consecutive Prime Numbers(水)

    POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...

  8. poj 2379 Sum of Consecutive Prime Numbers

                                                                                                        ...

  9. POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895 ...

随机推荐

  1. Fafa and the Gates(模拟)

    Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens ...

  2. Thunder团队第六周 - Scrum会议5

    Scrum会议5 小组名称:Thunder 项目名称:i阅app Scrum Master:翟宇豪 工作照片: 胡佑蓉同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblog ...

  3. c#笔记整理 关于继承与多态等

    [ 塔 · 第 二 条 约 定 ] c#面向对象基础 整理private.protected.public.abstract等的异同 public 公有访问.不受任何限制. private 私有访问. ...

  4. lintcode-189-丢失的第一个正整数

    189-丢失的第一个正整数 给出一个无序的正数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许 ...

  5. lol人物模型提取(三)

      提取出来的lol人物模型能让你知道一些有趣的信息,比如说给英雄量个身高啥的.   经测量,佐伊的身高应大于1m60,比想象中的着实高不少啊.   然后还应该把这个模型镜像对称一下,在3dsmax里 ...

  6. Python爬虫requests判断请求超时并重新发送请求

     下面是简单的一个重复请求过程,更高级更简单的请移步本博客: https://www.cnblogs.com/fanjp666888/p/9796943.html  在爬虫的执行当中,总会遇到请求连接 ...

  7. IO复用、多进程和多线程三种并发编程模型

    I/O复用模型 I/O复用原理:让应用程序可以同时对多个I/O端口进行监控以判断其上的操作是否可以进行,达到时间复用的目的.在书上看到一个例子来解释I/O的原理,我觉得很形象,如果用监控来自10根不同 ...

  8. asp.net mvc4 使用分部视图来刷新数据库

    前几天研究SSE,用浏览器做侦听后台数据库数据变化,如果有更新,就即时通过浏览器,使用SSE效果果然OK,侦听数据库有更新时马上会向浏览器通知有新数据,我还在浏览器里放了短音提示,但遇到一个问题,发出 ...

  9. f-measure[转]

    F-Measure又称为F-Score,是IP(信息检索)领域常用的一个评价标准,计算公式为: 其中β是参数,P是准确率(Precision),R是召回率(Recall). F1-Measure:当参 ...

  10. BZOJ 1406 密码箱(数论)

    很简洁的题目.求出x^2%n=1的所有x<=n的值. n<=2e9. 直接枚举x一定是超时的. 看看能不能化成有性质的式子. 有 (x+1)(x-1)%n==0,设n=a*b,那么一定有x ...