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. 普通Java类获取Spring的Bean的方法

    普通Java类获取Spring的Bean的方法 在SSH集成的前提下.某些情况我们需要在Action以外的类中来获得Spring所管理的Service对象. 之前我在网上找了好几好久都没有找到合适的方 ...

  2. 三:QJM HDFS高可用

    本文介绍的是HDFS的一种HA方案.虽然有checkpoint node \backup node等,但是不能实现自动的failover. http://hadoop.apache.org/docs/ ...

  3. Python3 循环表达式

    一 While循环 基本循环 while 条件: 执行内容 #循环体 ... #循环体 ... #循环体 # 若条件为真,执行循环体内容 # 若条件为假,不执行循环体内容 实例1(Python 3.0 ...

  4. 最小生成树——prim

    prim:逐“点”生成最小生成树 与Dijkstra不同的是:加入点到生成树中,不要考虑与源点的距离,而是考虑与生成树的距离 #include <iostream> #include &l ...

  5. windows编程入门最重要的

    要入门 Windows 编程,最重要的不是阅读什么教材,使用什么工具,而是先必须把以下几个对于初学者来说非常容易困惑的重要概念搞清楚: 1. 文字的编码和字符集.这部分需要掌握 ANSI 模式和 Un ...

  6. TCP系列33—窗口管理&流控—7、Silly Window Syndrome(SWS)

    一.SWS介绍 前面我们已经通过示例看到如果接收端的应用层一直没有读取数据,那么window size就会慢慢变小最终可能变为0,此时我们假设一种场景,如果应用层读取少量数据(比如十几bytes),接 ...

  7. IPReversePathFilter

    nstat TcpExtIPReversePathFilter for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do > echo 0 > $ ...

  8. 【week6】约跑App视频链接

    约跑视频链接发布在优酷,链接如下: http://v.youku.com/v_show/id_XMTc3NTcyNTcyNA==.html 秒拍视频连接: http://www.miaopai.com ...

  9. 【Docker 命令】- run命令

    docker run :创建一个新的容器并运行一个命令 语法: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS说明: -a stdin: 指 ...

  10. 简单名称值对节点类NameValuePair

    本类位于System.Data.dll中,名为:System.Data.Common.NameValuePair.主要用途是在DBConnectionString类中,解析ConnectionStri ...