题目大意

给定N,要求你计算用连续的素数的和能够组成N的种数

题解

先筛选出素数,然后暴力判断即可。。。

代码:

#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 10000
int prime[MAXN+5],cnt;
bool check[MAXN+5];
void get_prime()
{
cnt=0;
memset(check,false,sizeof(check));
for(int i=2;i<=MAXN;i++)
{
if(!check[i])
prime[cnt++]=i;
for(int j=0;j<cnt&&i*prime[j]<=MAXN;j++)
{
check[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
int main()
{
int n;
get_prime();
while(cin>>n&&n)
{
int count=0;
for(int i=0;i<cnt;i++)
{
int ans=0,j=i;
while(j<cnt&&ans<n)
{
ans+=prime[j];
j++;
}
if(ans==n) count++;
}
cout<<count<<endl;
}
return 0;
}

POJ2739 - Sum of Consecutive Prime Numbers(素数问题)的更多相关文章

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

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

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

  3. POJ2739 Sum of Consecutive Prime Numbers 确定某个数以内的所有素数

    参考:https://www.cnblogs.com/baozou/articles/4481191.html #include <iostream> #include <cstdi ...

  4. Sum of Consecutive Prime Numbers(poj2739)

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

  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. Sum of Consecutive Prime Numbers

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

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

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

  9. POJ.2739 Sum of Consecutive Prime Numbers(水)

    POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...

随机推荐

  1. 聊天工具实现winform端实现

    最近在找能够实现客户端点对点聊天的技术,通过github我发现了一个项目,它能够支持webscoket通讯,服务端是由c#socket完成. 我要的是winform端的通信,所以在他的基础上,增加了桌 ...

  2. Codeforces 612E - Square Root of Permutation

    E. Square Root of Permutation A permutation of length n is an array containing each integer from 1 t ...

  3. 【Bean】 这才是bean,一直没仔细看

    EJB是Enterprise Java Bean的缩写,一个Bean扮演着应用程序素材的角色.它包含有一个functional interface,一个life-cycle interface,以及一 ...

  4. httpcontext in asp.net unit test

    [TestMethod] [HostType("ASP.NET")] [UrlToTest("http://localhost:25153/qq/a.aspx" ...

  5. nodejs基础安装

    安装Nodejs需要从官网上下载一个最新的安装包,运行.我这里是win764位系统. 下载版本6.5.0 由于去外国的镜像上下载东西比较慢,淘宝为我们准备了国内的镜像.我们需要安装国内镜像的使用工具. ...

  6. 区域生长算法的一种C++实现

    区域生长算法是一种图像分割方法,能够将图像中具有相同特征的连通区域分割出来,同时保证较好的边缘信息. 区域生长算法的优点是简单,容易实现:但空间和时间复杂度较高,对分割图像要求较高,否则容易形成孔洞和 ...

  7. 关于c++字符串的while(*temp++)

    首先,上一段代码 static bool reverse_str(const char *str) { const char *temp=str; while(*temp++); temp-=; // ...

  8. WEB黑客工具箱之FireBug介绍

    Firefox扩展Firebug是一个全功能的Web 应用程序调试器,可以协助Web黑客洞悉复杂的Web 应用程序的内部工作机制.它有两种版本:一种可以跨浏览器使用的组件Firebug Lite,另一 ...

  9. loadrunner 一个诡异问题

    最近使用loadrunner压测一个项目的时候,发现TPS波动巨大.且平均值较低.使用jmeter压测则没有这个问题.经过多方排查发现一个让人极度费解的原因: 原脚本: //脚本其他代码...... ...

  10. *[codility]Number-of-disc-intersections

    http://codility.com/demo/take-sample-test/beta2010/ 这题以前做的时候是先排序再二分,现在觉得没有必要.首先圆可以看成线段,把线段的进入作为一个事件, ...