UVA 1210 Sum of Consecutive Prime Numbers
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的更多相关文章
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- 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 ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- poj 2379 Sum of Consecutive Prime Numbers
...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
随机推荐
- 再学习Webform页面生命周期
参考文章: 在vs2010,新建一个aspx页面,页面头部有一行代码: <%@ Page Language="C#" AutoEventWireup="true&q ...
- lintcode-13-字符串查找
字符串查找 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始).如果不存在,则返回 -1. 说明 ...
- java中多种方式读文件
转自:http://www.jb51.net/article/16396.htm java中多种方式读文件 一.多种方式读文件内容. 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取文件内 ...
- ICommand接口
WPF 中的命令是通过实现 ICommand 接口创建的.ICommand 的 WPF 实现是 RoutedCommand 类. WPF 中的主要输入源是鼠标.键盘.墨迹和路由命令.更加面向设备的输入 ...
- 【SQLAlchemy】SQLAlchemy修改查询字段列名
SQLAlchemy问题记录 company price quantity Microsoft Google Google Google 要实现脚本 select price, sum(quantit ...
- Activiti5工作流笔记一
介绍工作流 网上工作流的定义一大堆,这里就不去复制了,通俗的理解,工作流就是类似OA系统中请假审批.报销审批等一系列流程,下级提交的申请只有直系领导才能审批,其他人是没有权限的,而只有直系领导审批通过 ...
- 2018 杭电多校2 - Naive Operations
题目链接 Problem Description In a galaxy far, far away, there are two integer sequence a and b of length ...
- 【bzoj1798】[Ahoi2009]Seq 维护序列seq 线段树
题目描述 老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成. 有长为N的数列,不妨设为a1,a2,…,aN .有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一 ...
- POJ2115:C Looooops——题解
http://poj.org/problem?id=2115 题目大意:for(i=A;i!=B;i+=C),i的类型的范围为0<=a<1<<k exgcd裸题目. 设a=C, ...
- [辅助软件] 微信小程序开发资源汇总 接入指南
https://github.com/justjavac/awesome-wechat-weapp https://github.com/justjavac/awesome-wechat-weapp ...