原题链接

写个素数筛暴力打表一波就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. zookeeper会话超时 链接超时的排查

    1.会话概述 在ZooKeeper中,客户端和服务端建立连接后,会话随之建立,生成一个全局唯一的会话ID(Session ID).服务器和客户端之间维持的是一个长连接,在SESSION_TIMEOUT ...

  2. Git回滚到历史节点(SourceTree篇)

    转自:http://blog.csdn.net/u010416101/article/details/78142697.https://www.zhihu.com/question/48178380 ...

  3. [C++] Variable storage space

    Variable storage space

  4. Python守护进程(多线程开发)-乾颐堂

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  5. 前台的json数组转化为List<T>集合

    using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;u ...

  6. css中的三种基本定位机制

    css中的三种基本定位机制 a.普通文档流 b.定位:相对定位 绝对定位 固定定位 c.浮动 1.普通流中,元素位置由文档顺序和元素性质决定,块级元素从上到下依次排列,框之间的垂直距离由框的垂直mar ...

  7. 1 Python入门及计算机硬件知识

    一: Python是一种编程语言 语言: 语言是一种事物与另外一种事物沟通的介质 所以说编程语言是程序员和计算机之间实现沟通的桥梁 什么是编程?: 编程就是程序员用计算机所能理解的表达方式(编程语言) ...

  8. 在win10 + ie11上使用控件

    1.1. 在Win10+IE11上提示创建文件错误的问题 解决方法: 1.打开Internet选项   2.取消勾选启用保护模式   选择"不再显示此消息"

  9. JavaBugCharSequence

    目录 文章背景 目录 问题分析 问题解决 说明 参考文章 版本记录 文章背景 新建一个项目时候,不知道为什么,代码出现java.lang.CharSequence cannot be resolved ...

  10. ENVI 图像特征提取