POJ2739Sum of Consecutive Prime Numbers
http://poj.org/problem?id=2739
题意 :一个正整数能够表示为一个或多个连续素数和,给你一个正整数,让你求,有多少个这样的表示。例如:整数53有两种表示方法,5+7+11+13+17和53,41有三种表示方法,2+3+5+7+11+13,11+13+17还有41,而整数20没有这样的表示方法。
思路 :因为取值到10000,所以先素数打表,然后枚举所有的表示方法中连续的素数里最小的那个即可。
#include <iostream> using namespace std; const int maxp = ,n = ;
int prime[maxp],total = ;
bool isprime(int k)
{
for(int i = ; i < total ; i++)
if(k % prime[i] == )
return false ;
return true ;
}
int main()
{
for(int i = ; i <= n ; i++)
{
if(isprime(i))
prime[total++] = i ;
}
prime[total] = n+ ;
int m ;
while(cin>>m &&m)
{ int ans = ;//次数初始化为0
for(int i = ; m >= prime[i] ; i++)
{
int cnt = ;//求连续素数的和
for(int j = i ; j < total&&cnt < m ; j++)
cnt += prime[j] ;
if(cnt == m)
++ans ;
}
cout<<ans<<endl ;
}
return ;
}
POJ2739Sum of Consecutive Prime Numbers的更多相关文章
- 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 ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- poj 2739 Sum of Consecutive Prime Numbers 小结
Description Some positive integers can be represented by a sum of one or more consecutive prime num ...
- 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 ...
- 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 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- Sum of Consecutive Prime Numbers(素数打表+尺取)
Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...
随机推荐
- 安全接口 interface --显示实现接口
前言:当我们定义接口的成员的时候不需要写访问控制符,因为它是默认public的,也只能是public.当一个类要实现这个接口的时候,自然要公开其成员.一直以来我都这么做. interface Inte ...
- KindEditor配置步骤
KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所见即所得编辑效果,兼容IE.Firefox.Chrome.Safari.Opera等主流浏览器. KindEditor ...
- 大家注意:升级 win8.1 火狐浏览器 谷歌浏览器 搜狗五笔输入法 都不能用啦
大家注意:升级 win8.1 火狐浏览器 谷歌浏览器 搜狗五笔输入法 都不能用啦 我的电脑64位 win8 thinkpad e531,8G内存 刚在线升级完8.1,发现这些问题,大家注意,有知道问题 ...
- Session 的配置和特性
session的配置 对于session的配置是php.ini中配置 session数据都是保存在文本文件中 设置session文件的保存位置 说明: 默认是保存在windows/temp目录 ...
- Oracle创建新用户
1.以DBA身份登录 $ sqlplus sys/eastcom@ORCL as sysdba(在命令窗口下) 也可以使用PL/SQL 2.创建临时表空间 create temporary table ...
- AspectJ的简单使用
aspectj是一款优秀的面向切面的编程框架,下面就简单介绍一下入门教程吧: 1.官网下载AspectJ的jar包,我这里下的是最新版本1.8.7的. 2.因为AspectJ.jar 是一个可执行的j ...
- Cursor--游标
游标--cursor['kɜːsə] 概念: 在执行SQL语句时,Oracle服务器将分配一个内存区域,不仅存储这个语句,还存储语句的结果 — 称为 ...
- 什么是MBR?(含图解)
Mbr位于磁盘的0柱面,0磁头,1扇区. MBR 有三部分构成,主引导程序,硬盘分区表DPT和,硬盘的有效标志55AA.在512个字节的主引导扇区里. 主引导程序占446个字节,dpt占6 ...
- Maven使用总结
1.pom.xml文件中添加新的库 在中央仓库找不到你想要的jar的时候,可以在pom.xml中添加附加的库,语法如下 <repositories> <repository> ...
- DTCMS中部分IE8不支持webupload上传附件的控件,更改为ajaxfileupload
dialog\dialog_attach.aspx <!DOCTYPE html> <html> <head> <meta http-equiv=" ...