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> # ...
随机推荐
- OFFICE_EXCEL_Combine text from two or more cells into one cell.
Excel Enter and format data Layout Combine text from two or more cells into one cell Combine t ...
- 关于method not exist:think\db\Query->render错误解决方法
{volist name="Teachers" id="Teachers" key="key"} <tr> <td> ...
- SVN:验证位置时发生错误解决方案
1. 2. 3.preferencens > svn >svn接口-选择SVNKit(Pure Java)设置后,再引用svn路径后,直接弹出输入用户名和密码就对了. 4.
- March 12 2017 Week 11 Sunday
I learned the value of hard work by working hard. 只有真的努力了,才会知道努力的价值. I know the value of hard work, ...
- Jerry的Fiori原创文章合集
我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(三) 激动人心的时刻到啦,实现1v1聊天
看起来挺简单,细节还是很多的,好,接上一篇,我们已经成功连接singalR服务器了,那么剩下的内容呢,就是一步一步实现聊天功能. 我们先看看缺什么东西 点击好友弹框之后,要给服务器发消息,进入组Gro ...
- Latex 编辑器安装
MiKTex + TexStudio 1. 下载安装MiKTex,从http://www.miktex.org/下载basic-miktex-2.9.5872-x64.exe,一路默认安装... 或者 ...
- 【luogu P3375 KMP字符串匹配】 模板
题目链接:https://www.luogu.org/problemnew/show/P3375 精华:在每次失配后不从头匹配而是尝试找一个新的开始并且是新开始的位置最长的相同前缀和后缀. 实际上KM ...
- 【luogu P2065 [TJOI2011]卡片】 假题解
题目链接:https://www.luogu.org/problemnew/show/P2065 辣鸡匈牙利,没有优化贼鸡儿慢 // luogu-judger-enable-o2 #include & ...