参考:https://www.cnblogs.com/baozou/articles/4481191.html

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e4+;
bool prime[N];
void primemap()
{
memset(prime,true,sizeof(prime));
prime[]=prime[]=false;
for (int i=;i<N;i++)
{
if (prime[i])
{
for (int j=*i;j<N;j+=i)
{
prime[j]=false;
}
}
}
}
int solve(int x)
{
int ans=;
for (int i=;i<=x;i++)
{
if (prime[i])//遍历以素数开头的和,所以要先判断!
{
int sum=;
for (int j=i;j<=x;j++)
{
if (prime[j])
{
sum+=j;
}
if (sum==x)
{
ans++;
break;
}
if (sum>x)
{
break;
}
}
}
}
return ans;
}
int main()
{
int in;
primemap();
while (cin>>in&&in)
{
cout<<solve(in)<<endl;
} return ;
}

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(素数问题)

    题目大意 给定N,要求你计算用连续的素数的和能够组成N的种数 题解 先筛选出素数,然后暴力判断即可... 代码: #include<iostream> #include<cstrin ...

  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. JAVA利用jxl读取Excel内容

    JAVA可以利用jxl简单快速的读取文件的内容,但是由于版本限制,只能读取97-03  xls格式的Excel. import java.io.File; import java.io.FileInp ...

  2. libxml2库函数详解

    许多事物符合80/20法则,libxml中也是20%的函数提供了80%的功能.下面的列表列出了libxml的主要函数及其用法说明. 1.   全局函数说明 头文件引用 xml2config --cfl ...

  3. Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired,

    Did not receive a reply. Possible causes include: the remote application did not send a reply, the m ...

  4. 使用Vue做评论+localStorage存储(js模块化)

    未分模块化 html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  5. LeetCode15.三数之和 JavaScript

    给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三元组. ...

  6. AutoCAD笔记

    1.等距离复制:使用菜单栏下“修改->阵列”功能或右侧快捷方式,可以轻松复制,以下是阵列设置界面 2.快捷键-图案填充和渐变色:H+空格 3.画图时时常会用到Ctrl+V,但难免会按成了Ctrl ...

  7. Dubbo源码分析之ExtensionLoader加载过程解析

    ExtensionLoader加载机制阅读: Dubbo的类加载机制是模仿jdk的spi加载机制:  Jdk的SPI扩展加载机制:约定是当服务的提供者每增加一个接口的实现类时,需要在jar包的META ...

  8. 轻量ORM-SqlRepoEx (四)INSERT、UPDATE、DELETE 语句

    *本文中所用类声明见上一篇博文<轻量ORM-SqlRepoEx (三)Select语句>中Customers类 一.增加记录 1.工厂一个实例仓储 var repository = Rep ...

  9. DLL DEF文件编写方法 VC++ 调用、调试DLL的方法 显式(静态)调用、隐式(动态)调用

    DLL 文件编写方法: 1.建立DLL工程 2.声明.定义要导出的函数 BOOL WINAPI InitDlg( HWND hTabctrl,TShareMem* pTshare,CRect* prc ...

  10. JS的Ajax对象

    //1.得到对象    var ajax = new XMLHttpRequest(); //2.建立连接    ajax.open('post','./2.php',true); /*       ...