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 ...
随机推荐
- PHP学习笔记--入门篇
PHP学习笔记--入门篇 一.Echo语句 1.格式 echo是PHP中的输出语句,可以把字符串输出(字符串用双引号括起来) 如下代码 <?php echo "Hello world! ...
- swift基础知识学习
用let来声明常量,用var来声明变量 声明变量: var x = 0.0, y = 0.0, z = 0.0 var welcomeMessage: String 常量和变量的命名 你可以用任何 ...
- less使用001
官网: http://lesscss.org/ . 中文文档直接百度搜索less,能找到N多网站提供的支持. less-gui,使用国产的koala, 其中文帮助文档地址. 拖拽一个目录到考拉就新建了 ...
- requirejs实验001.对我来说,用AMD的方式来组织代码并不轻松.
http://www.requirejs.org/ http://www.requirejs.cn/ http://requirejs.readthedocs.org/en/1.0.1/ 目录结构: ...
- 翻转单词顺序VS左旋转字符串
题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变.句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理.例如输入“I am a student.”,则输出“student ...
- Bugzilla 使用指南
Bugzilla安装见前一篇博客,本篇文章主要关注于如何高效合理的使用Bugzilla,作为为公司内部人员的培训使用指南. Bugzilla是一个开源的缺陷跟踪系统,它可以管理软件开发过程中缺陷的提交 ...
- Linux RedHat无法安装软件问题(No package gcc available. Nothing to do)
在一个新的Linux服务器上安装nginx的时候,命令都不能解析,缺少gcc编辑器,安装gcc的命令也出错. [root@localhost ~]# yum -y install gcc Loaded ...
- Uploadify 3.2 not work in IE10
uploadify版本:Uploadify Version 3.2.1 現象:在IE10下uploadify上傳按鈕點擊失效 解決方案:替換uploadify下的js引用包 替換文件下載地址: 下载地 ...
- CSS3中的变形处理(transform)属性
在CSS3中,可以利用transform功能来实现文字或图像的旋转.扭曲.缩放.位移.矩阵.原点这六种类型的变形处理,下面将详细讲解transform的使用. 变形--旋转 rotate() div. ...
- PHP随机生成广告图片的实例 代码
PHP随机生成广告图片: <?php /* +------------------------------------------------------------------+ | Mi ...