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> # ...
随机推荐
- 如何修改Fiori Launchpad里Tile计数调用的时间间隔
Fiori launchpad里的Tile上有一个数字,例如下图My Leads的例子:每隔指定的时间间隔,会向后台发起一次数据请求,读取当前Lead的个数. 这个请求可以在Chrome Develo ...
- OC 成员变量 ( -> 使用 )
@interface Student : NSObject { // @public // @protected // @private // 默认的作用域是@protected int age; @ ...
- c++互斥锁的实现
class IMyLock { public: virtual ~IMyLock(){} ; ; }; class Mutex : public IMyLock { public: Mutex(); ...
- 关于rapidxml无法解析中文路径问题
先放结果 setlocale(LC_ALL, ""); rapidxml::file<> f(szPath); setlocale(LC_ALL, "C&qu ...
- BAT的云
近期,关于用国内那家云非常纠结! 我也来说道说道各家云. 首先,说说我想要的云服务(按优先级): 0.最好能提供二级域名.移动互联网时代,顶级域名必需要吗?在手机浏览器上输入长长的域名非常蛋痛(即不要 ...
- 课堂笔记——while循环
用 while循环 1.100以内所有数的和 static void Main1(string[] args) //不是自己做的 { //100以内所有数的和 ; ; //初始条件 ) //循环条件 ...
- stn,spatial transformer network总结
对整篇paper的一个总结:https://blog.csdn.net/xbinworld/article/details/69049680 github:1.https://github.com/D ...
- ProjectServer如何让系统管理员模拟普通用户创建自己的时间表
public bool ProcessTimesheet(Guid siteGuid, Guid tsGuid, string lcid, string userName, bool submitSt ...
- Vue开发 localhost 替换成 本机ip无法访问
新版 vue-cli(@3.10.10) 构建的项目.localhost 替换成本机 ip 地址之后无法访问.但是替换成 127.0.0.1 可以访问 找到 config 文件夹下面的 index.i ...
- 执行计划sql
我准备开始分析并优化我的查询.在分析之前,我想到了一些问题. MS-SQL Server什么时候使用"Table Scan"? MS-SQL Server什么时候使用"I ...