POJ2739 - Sum of Consecutive Prime Numbers(素数问题)
题目大意
给定N,要求你计算用连续的素数的和能够组成N的种数
题解
先筛选出素数,然后暴力判断即可。。。
代码:
#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 10000
int prime[MAXN+5],cnt;
bool check[MAXN+5];
void get_prime()
{
cnt=0;
memset(check,false,sizeof(check));
for(int i=2;i<=MAXN;i++)
{
if(!check[i])
prime[cnt++]=i;
for(int j=0;j<cnt&&i*prime[j]<=MAXN;j++)
{
check[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
int main()
{
int n;
get_prime();
while(cin>>n&&n)
{
int count=0;
for(int i=0;i<cnt;i++)
{
int ans=0,j=i;
while(j<cnt&&ans<n)
{
ans+=prime[j];
j++;
}
if(ans==n) count++;
}
cout<<count<<endl;
}
return 0;
}
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 确定某个数以内的所有素数
参考:https://www.cnblogs.com/baozou/articles/4481191.html #include <iostream> #include <cstdi ...
- 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> # ...
随机推荐
- WPF读书笔记(第一天)
今天开始学习WPF,大家都推荐<深入浅出WPF>这本书,一下是我觉得此书中重要的地方,记录下来以便以后回顾,也希望其他人看到了对你们有帮助. 1.XAML是可扩展应用程序标记语言 是WPF ...
- Custome Buble Data Point
<navigation:Page xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/to ...
- 5.MVC框架开发(强类型开发,控制器向界面传递数据的几种方法)
界面表单中的表单元素名字和数据库表的字段名相一一映射(需要哪个表的数据就是那个表的模型(Model)) 在View页面中可以指定页面从属于哪个模型 注:以上的关系可以通过MVC的强类型视图开发来解决我 ...
- Windows脚本
最近项目测试比较麻烦,要启动好几个command窗口,手敲之类的有些繁琐,于是研究了一下windows脚本,实现以下功能: 懒人吗,参数意义顺序比较懒得记,所以需要友好参数提示: 根据参数数量决定启动 ...
- BZOJ 1227 虔诚的墓主人
Description 小W 是一片新造公墓的管理人.公墓可以看成一块N×M 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地.当地的居民都是非常虔诚的基督徒,他们愿意提前为自己 ...
- struts2用了哪几种模式
代理模式 责任连模式 ActionVacation 迭代模式
- 我的PHP之旅--认识PHP
PHP是什么? php是一个脚本语言,它运行在服务器端并会以纯文本的形式返回到服务器,它是免费的. php可以对数据库中的数据进行:增删改查,可以对数据进行加密,接收表单. php的文件后缀是.php ...
- java线程池的使用与详解
java线程池的使用与详解 [转载]本文转载自两篇博文: 1.Java并发编程:线程池的使用:http://www.cnblogs.com/dolphin0520/p/3932921.html ...
- SQL分组查询GroupBy
一.分组查询1.使用group by进行分组查询在使用group by关键字时,在select列表中可以指定的项目是有限制的,select语句中仅许以下几项:〉被分组的列〉为每个分组返回一个值得表达式 ...
- c++学习之旅-Cygwin+Eclipse ide for c++
一,cygwin下载完毕后配置系统环境片两path指向cygwin/bin 二,eclipse设置 2.1 设置工作目录的cygwin映射 cygwin/d ->d:\ 2.2设置编译 下面新建 ...