原题链接

写个素数筛暴力打表一波就AC了;

#include <iostream>

using namespace std;

const int N = 10001;

int i, j, NotPrime[N];
long long sum[N];
void GetNotPrime()
{
for( i=2; i<=N; i++ )
if( !NotPrime[i] )
for( j = i+i; j<=N; j+=i )
NotPrime[j] = 1;
} int k;
void GetPrimeSum()
{
sum[0] = 0;
sum[1] = 2;
k = 1;
for( i=3; i<N; i++ )
if( !NotPrime[i] )
{
sum[k+1] = sum[k] + i;
k++;
}
} int main()
{
int n;
GetNotPrime();
GetPrimeSum();
while( cin >> n && n )
{
int cnt = 0;
for( i=0; i<k; i++ )
{
for( j=i+1; j<k; j++)
{
if( n == sum[j] - sum[i] )
{
cnt++;
}
}
}
cout << cnt << endl;
}
return 0;
}

UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

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

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

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

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

  4. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  5. POJ 2739. Sum of Consecutive Prime Numbers

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

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

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

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

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

  8. 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 ...

  9. Sum of Consecutive Prime Numbers

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

  10. Sum of Consecutive Prime Numbers(poj2739)

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

随机推荐

  1. 14-python登入教务网(python+bs4)

    用request先得到到session对象,用其去放送请求,会自动保存cookie. 模拟有验证码的登入步骤: 1.发送请求登入页面: 2.分析验证码的地址,以及要将登入请求发往的地址(可以先输入错的 ...

  2. redis 面试题2

    使用过Redis分布式锁么,它是什么回事? 先拿setnx来争抢锁,抢到之后,再用expire给锁加一个过期时间防止锁忘记了释放. 这时候对方会告诉你说你回答得不错,然后接着问如果在setnx之后执行 ...

  3. eclipse在线安装mybatis generator插件

    转自:http://blog.csdn.net/u012283609/article/details/67640433 安装步骤: 打开eclipse菜单栏help–>Eclipse Marke ...

  4. asp.net webform过滤器(注意我们可以在拦截请求的同时设置回调函数)

    .过滤器代码 public class PageFilter : IHttpModule { public String ModuleName { get { return "PageFil ...

  5. jdk1.7 环境变量配置

    Windows系统中设置环境变量如下图右击“我的电脑”,选择“属性”. 点击“高级”选项卡,选择“环境变量”.  在“系统环境变量”中设置上面提到的3个环境变量,如果变量已经存在就选择“编辑”,否则选 ...

  6. Perl 学习笔记-子程序

    1.定义子程序 使用sub关键字定义 ;   子程序名和标识符同要求, 但是有的特殊的可以用 &符号;  子程序是全局的, 不需要再使用前声明;  重名函数后者覆盖前者. sub roger{ ...

  7. 【转】OJ提交题目中的语言选项里G++与C++的区别

    原文链接:http://blog.polossk.com/201405/c-plus-plus-g-plus-plus G++? 首先更正一个概念,C++是一门计算机编程语言,G++不是语言,是一款编 ...

  8. ubuntu 16.04快速建lvm

    1.准备2块虚拟硬盘 在执行下面之前先安装:lvm和mkfs.xfs apt install lvm2 -y apt install xfsprogs dd if=/dev/zero of=ceph- ...

  9. linux 扩展权限

    默认权限     每一个终端都拥有一个umask属性,来确定新建文件,文件夹的默认权限 umask使用数字权限方式表示,如:022 新建目录的默认权限是:777-umask; 新建文件的默认权限是:6 ...

  10. Spring事务管理—aop:pointcut expression 常见切入点表达式及事物说明

    例: <aop:config>  <aop:pointcut expression="execution(* com.xy.service.*.*(..))"   ...