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. Appcn 移动开发 前台与服务器数据交互

    第一次写.嘿嘿. 言归正传,这几天开始学习移动开发,使用的是Appcan平台.Appcan平台采用HTML5+CSS3做开发 实现跨平台,正好可以满足我们的业务需求. Appacn和数据库进行交互的方 ...

  2. javascript笔记——点击按钮(或超链接)如何跳转到另外一个页面并执行目标页面的js函数

    页面跳转同时执行js代码$(function(){});url参数传递 标题的前半部分其实不必赘述,按钮也可以换成超链接.. 假设是需要在A页面上的一个按钮,点击后跳转到B页面,传一些参数后且并B页面 ...

  3. 用于主题检测的临时日志(594fb726-af0b-400d-b647-8b1d1b477d72 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

    这是一个未删除的临时日志.请手动删除它.(f8322da6-c527-47fb-98d2-f12a7d814d19 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

  4. xamarin android——数据绑定到控件(二)

    本示例为通过媒体内容提供器获取本机中的图片显示在Gallery中. 活动中简单的初始化代码 private void InitGallery() { Gallery gallery = FindVie ...

  5. DTCMS中部分IE8不支持webupload上传附件的控件,更改为ajaxfileupload

    dialog\dialog_attach.aspx <!DOCTYPE html> <html> <head> <meta http-equiv=" ...

  6. 利器: 用Siege做Web服务器压测

    用「Web压测」关键词检索,能找到好多进行压测的工具,比如ab.Http_load.Webbench.Siege这些,不过今天并不是要对这些工具做对比,毕竟我们只是想得到一个结果.本文主要介绍Sieg ...

  7. laravel 框架 开源的cms推荐

    laravel 框架写的开源的cms系统 TypiCMS系统 多语言和模块化的CMS Laravel 5.2框架 下载地址:https://github.com/TypiCMS/Base Bootst ...

  8. 使用Hibernate 拦截执行sql语句,并输出sql语句,获取sql语句

    重建包名 org.hibernate.type.descriptor.sql 重建类BasicBinder 代码如下 package org.hibernate.type.descriptor.sql ...

  9. mysql中使用update select

    UPDATE t_user INNER JOIN t_shake ON t_shake.user_id = t_user.user_id SET t_user.shake_total_num = t_ ...

  10. php 随机显示图片的函数(实例)

    转自:http://www.jbxue.com/article/12695.html   发布:thatboy   来源:Net     [大 中 小] 本文分享一个php实现的随机显示图片的函数,可 ...