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. jQuery 自定义事件的学习笔记

    jquery中提供了两种方法可以绑定自定义事件: bind()和one()而绑定的自定义事件的触发,必须得用jquery中的trigger()方法才能触发. 我们先来看on事件  代码如下 复制代码 ...

  2. Memcached学习(一)

    1.Memcached是什么? 引用维基百科上得简介,Memcached 是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,目前已被诸如Facebook等许多 ...

  3. Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)C粉丝与汉诺塔

    题目描述 苟利国家生死以,岂因福祸避趋之?作为ACM真正的粉丝,应该都听闻过汉诺塔问题,汉诺塔问题是这样的: 有三根柱子,编号A,B,C柱,初始情况下A柱上有n个盘子,小盘子在上大盘子在下,n个盘子大 ...

  4. SQL server 常见用法记录

        -- ============================================= -- Author:                tanghong -- Create da ...

  5. 《C#高级编程》

    <C#高级编程>是一本真正的C#技术"字典",长达36章.1200页的内容-涵盖了C#..NET各个方面的基础内容. 当然这本书我没有真正的看过一遍,只是在需要的时候才 ...

  6. 3月3日[Go_deep]Populating Next Right Pointers in Each Node

    原题:Populating Next Right Pointers in Each Node 简单的链表二叉树增加Next节点信息,没什么坑.不过还是WA了两次,还是有点菜,继续做,另外leetcod ...

  7. C语言中格式化输出的转换说明的fldwidth和precision解析

    首先说什么是C语言的格式化输出,就是printf和它的几个变种(grep -E "v?(sn|s|f)printf").像这些函数都有一个参数format,format中可以加点转 ...

  8. T-SQL数组循环

    T-SQL对字符串的处理能力比较弱,比如要循环遍历象1,2,3,4,5这样的字符串,如果用数组的话,遍历很简单,但是T-SQL不支持数组,所以处理下来比较麻烦.下边的函数,实现了象数组一样去处理字符串 ...

  9. DEV GridControl表格数据源为空在表格中间显示提醒字符

    private static void gv_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.Custo ...

  10. VB6-操作数据库

    平常搞数据库操作多了就想把经常用的内容放在一起,我也懒,在一本书里的工程例子挑了一个bas,修修改改,凑合这用吧. Public strCnn As String '数据库连接字符串 Public A ...