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

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

  1. #include<cstdio>
  2. #define N 10001
  3. using namespace std;
  4. int cnt,p[N],sum[N],ans[N];
  5. bool v[N];
  6. int main()
  7. {
  8. for(int i=;i<N;i++)
  9. {
  10. if(!v[i])
  11. {
  12. v[i]=true;
  13. p[++cnt]=i;
  14. }
  15. for(int j=;j<=cnt;j++)
  16. {
  17. if(i*p[j]>=N) break;
  18. v[i*p[j]]=true;
  19. if(i%p[j]==) break;
  20. }
  21. }
  22. for(int i=;i<=cnt;++i) sum[i]=sum[i-]+p[i];
  23. for(int r=;r<=cnt;r++)
  24. for(int l=r;l;l--)
  25. {
  26. if(sum[r]-sum[l-]>=N) break;
  27. ans[sum[r]-sum[l-]]++;
  28. }
  29. int n;
  30. while(scanf("%d",&n)!=EOF)
  31. {
  32. if(!n) return ;
  33. printf("%d\n",ans[n]);
  34. }
  35. }

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. 再学习Webform页面生命周期

    参考文章: 在vs2010,新建一个aspx页面,页面头部有一行代码: <%@ Page Language="C#" AutoEventWireup="true&q ...

  2. lintcode-13-字符串查找

    字符串查找 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始).如果不存在,则返回 -1. 说明 ...

  3. java中多种方式读文件

    转自:http://www.jb51.net/article/16396.htm java中多种方式读文件 一.多种方式读文件内容. 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取文件内 ...

  4. ICommand接口

    WPF 中的命令是通过实现 ICommand 接口创建的.ICommand 的 WPF 实现是 RoutedCommand 类. WPF 中的主要输入源是鼠标.键盘.墨迹和路由命令.更加面向设备的输入 ...

  5. 【SQLAlchemy】SQLAlchemy修改查询字段列名

    SQLAlchemy问题记录 company price quantity Microsoft Google Google Google 要实现脚本 select price, sum(quantit ...

  6. Activiti5工作流笔记一

    介绍工作流 网上工作流的定义一大堆,这里就不去复制了,通俗的理解,工作流就是类似OA系统中请假审批.报销审批等一系列流程,下级提交的申请只有直系领导才能审批,其他人是没有权限的,而只有直系领导审批通过 ...

  7. 2018 杭电多校2 - Naive Operations

    题目链接 Problem Description In a galaxy far, far away, there are two integer sequence a and b of length ...

  8. 【bzoj1798】[Ahoi2009]Seq 维护序列seq 线段树

    题目描述 老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成. 有长为N的数列,不妨设为a1,a2,…,aN .有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一 ...

  9. POJ2115:C Looooops——题解

    http://poj.org/problem?id=2115 题目大意:for(i=A;i!=B;i+=C),i的类型的范围为0<=a<1<<k exgcd裸题目. 设a=C, ...

  10. [辅助软件] 微信小程序开发资源汇总 接入指南

    https://github.com/justjavac/awesome-wechat-weapp https://github.com/justjavac/awesome-wechat-weapp ...