POJ2739 Sum of Consecutive Prime Numbers 确定某个数以内的所有素数
参考: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 确定某个数以内的所有素数的更多相关文章
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- 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 ...
- POJ2739 - Sum of Consecutive Prime Numbers(素数问题)
题目大意 给定N,要求你计算用连续的素数的和能够组成N的种数 题解 先筛选出素数,然后暴力判断即可... 代码: #include<iostream> #include<cstrin ...
- Sum of Consecutive Prime Numbers(poj2739)
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22019 Ac ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
随机推荐
- May 18th 2017 Week 20th Thursday
The greater the struggle, the more glorious the triumph. 挑战愈艰巨,胜利愈辉煌. Sometimes it would be better t ...
- 原生JavaScript实现JSON合并(递归深度合并)
// 遇到相同元素级属性,以(minor)为准 // 不返还新Object,而是main改变 function mergeJSON(minor, main) { for(var key in mino ...
- 一点一点学写Makefile(4) - 编译时指定宏参数
我们在项目中有时为了方便会自定义一些与项目无关的功能,例如打印输出一些提示信息.将关键协议生成文件等,但是如果每次都通过修改代码的方法来实现,测试部门就会认为你改的这些代码可能会带来其他问题.对于这种 ...
- Jmeter入门10 jmeter加密串处理方式2:BeanShell PreProcessor
上一个博客讲了方式一:函数助手__digest加密,BeanShell PreProcessor也可以用java代码进行处理 线程组.参数.请求都直接使用上一个博客的. 第一步 添加BeanShell ...
- Hive创建外部表以及分区
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sheismylife/article/details/27874943 创建带分区的外部表 创建外部 ...
- python-文件基本操作(二)
在上一篇文章中,简单介绍了打开文件的方法以及关于读.写.追加的操作,点击此处查看. 在此篇文章中,继续介绍另外一种打开文件的方法和几种同时读写的模式. 一.打开文件方法:with 使用file()或o ...
- mysql安装下载
简单介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最 ...
- 【洛谷P1100】高低位交换
高低位交换 题目链接 这道题非常水,我是用位运算做的 a=n>>16 二进制的“高位”b=n-(a<<16) 二进制的“低位”ans=(b<<16)+a 转换 #i ...
- 前端静态文件如何应对HTTPS的到来
近几年,越来越多的网站开始支持https,我们可以看到国外的比如github.谷歌.facebook:国内的有百度.淘宝.博客园.coding.net.worktile等一系列的网站. 我再最近的开发 ...
- Aspose.cell C# 操作excel(通过批注信息给单元格赋值、批注信息获取公式得出结果并转PNG)
if (fileName == "") return ""; var CurrentRow = 0; Workbook work = new Workbook( ...