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的更多相关文章

  1. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  2. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  3. POJ2739 Sum of Consecutive Prime Numbers(尺取法)

    POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...

  4. poj 2739 Sum of Consecutive Prime Numbers 小结

     Description Some positive integers can be represented by a sum of one or more consecutive prime num ...

  5. 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 ...

  6. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS   Memory Limit: 6 ...

  7. poj 2739 Sum of Consecutive Prime Numbers 尺取法

    Time Limit: 1000MS   Memory Limit: 65536K Description Some positive integers can be represented by a ...

  8. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

  9. Sum of Consecutive Prime Numbers(素数打表+尺取)

    Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...

随机推荐

  1. ListView onItemClick(AdapterView<?> parent, View view, int position, long id)参数详解

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { parent.getA ...

  2. Bitmap、CBitmap、HBITMAP以及BITMAP的相互转换

    Bitmap.CBitmap.HBITMAP以及BITMAP的相互转换 构建CBitmapCBitmap bmp;bmp.LoadBitmap(ID); 构建HBITMAPHBitmap = (HBI ...

  3. 你早该这么玩Excel 读书笔记

    1. Excel用来分析数据,至少要有一份原始数据和对于的分类汇总数据,这两种数据在一项任务中,应该是存放在同一个Excel文档中的,在书籍中,把他们叫做源数据表和分类汇总表.用户输入源数据表,根据相 ...

  4. mysql 之路目录

    数据库介绍.常见分类 Mysql入门 Mysql安装配置 Mysql多实例安装配置 Mysql常用基本命令 Mysql数据库备份和恢复 Mysql日志 Mysql逻辑.物理备份和增量恢复 Mysql字 ...

  5. Nhibernate的log4net和系统的log4net使用技巧

    NHibernate定义了两个logger:NHibernate和NHibernate.SQL.我们可以分别配置这两个logger.在App.config文件中<root>标签前边添加如下 ...

  6. 弹性布局学习-详解 justify-content(三)

    弹性布局学习-详解 justify-content(三)

  7. NodeJS + Socket.io聊天服务器连接数达到1024后就连不上了

    如果是亚马逊的Engine Yard服务器,解决办法为: 1.查看端口占用情况,找到nodejs进程号,例如我这里是8000端口 lsof -i:8000  找到pid 例如为 8213 2.设置no ...

  8. javascript跨域解决方案

    最近遇到了https跨域访问http域的问题,很多朋友理所当然的认为简单,问题是https跨域访问到http域上的资源,会进行相互通信,没有解决该问题,只能把外部资源扔到了新浪的sae上,通过http ...

  9. NVIDIA显卡设置提升MineCraft流畅度

    很喜欢MineCraft(我的世界)这款游戏.可09年Y450的配置现在看来有点弱,尽管将Y450的CPU升级至了2.8Ghz的T9600,内存升级至1066Mhz的4G双通道内存,硬盘更换为128G ...

  10. if...else..的错误用法

    1.最近在写js代码完成一个前段DOM操作的函数时,自己错误的使用了if..else..控制体.为什么是错误的呢?看看我的 代码你就明白了: document.getElementsByClassNa ...