参考: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. Vim直接打开Tampermonkey网址的方法。

    根据tampermonkey利用@require调用本地脚本的方法,比如我电脑上保存了Tampermonkey脚本a.user.js和它调用的a.js, 想在Vim编辑这两个文件时,都能一键打开网页里 ...

  2. SQA1

    客观地验证软件项目产品和工作是否遵循恰当的标准.步骤和需求. 2.将软件质量保证工作及结果通知给相关组别和个人.

  3. Catalan数列

    引入 今天听学长讲了卡特兰数列后对其有了更深的认识,在此完善了一下之前的博客加以总结. 首先用一个经典的例子来描述一下Catalan数列,我们有一个1~n的数列和一个大小为n的栈,我们有如下两种操作: ...

  4. hack-checkbox

    checkbox选择按钮要用我们自己的样式,看到这个的时候,很可能会以为需要checkbox才能实现,用css可能很难.其实狠简单. <style> .checkbox input{ di ...

  5. POJ 3067 Japan 【树状数组经典】

    题目链接:POJ 3067 Japan Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32076   Accep ...

  6. Windows后门小计

    嗅探欺骗: 在目标机上安装嗅探工具窃取管理员的密码 放大镜替换: 构造批处理: @echo off net user gslw$ test168 /add net localgroup adminis ...

  7. Maven plugin 插件

    1.maven-surefire-plugin简介: Maven在构件时执行到测试的生命周期时,会使用maven-surefire-plugin运行测试用例,背后执行的Junit或者TestNG的测试 ...

  8. 【luogu P2746 [USACO5.3]校园网Network of Schools】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2812 注意:判断出入度是否为0的时候枚举只需到颜色的数量. 坑点:当只有一个强连通分量时,不需要再添加新边. ...

  9. 【题解】UVA756 Biorhythms (中国剩余定理)

    UVA756:https://www.luogu.org/problemnew/show/UVA756 思路 几乎是裸的中国剩余定理模板题 但是需要注意的是此题并不是求最小正整数解 而是求大于d的解 ...

  10. 简述 private、 protected、 public、 internal 修饰符的访问权限

    简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在该类的内部才可以访问. protected : 保护成员,该类内部 ...