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

Description

Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime 
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. 
Your mission is to write a program that reports the number of representations for the given positive integer.

Input

The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero.

Output

The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.

Sample Input

2
3
17
41
20
666
12
53
0

Sample Output

1
1
2
3
0
0
1
2 思路:打表,不管是dp还是简单的列举首尾端点
问题:看错题意以为3 5 5 7 是允许的方式
#include <cstdio>
#include <cstring>
using namespace std;
int method[10001][1300];
int dp[10001];
bool isntprime[10001];
int heap[1300],cnt;
void calprime(){
method[2][0]=1;
dp[2]++;
heap[cnt++]=2;
for(int i=3;i<10001;i+=2){
if(!isntprime[i]){
heap[cnt]=i;
method[i][cnt++]=1;dp[i]++;
for(int j=3;i*j<10001;j+=2){
isntprime[i*j]=true;
}
}
}
}
void caldp(){
for(int i=2;i<10001;i++){
for(int j=0;j<cnt;j++){
if(method[i][j]!=0){
if(j<cnt-1&&i+heap[j+1]<10001){
method[i+heap[j+1]][j+1]+=method[i][j];
dp[i+heap[j+1]]+=method[i][j];
}
}
}
}
}
int main(){
calprime();
caldp();
int n;
while(scanf("%d",&n)==1&&n){
printf("%d\n",dp[n]);
}
return 0;
}

  

poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  2. POJ.2739 Sum of Consecutive Prime Numbers(水)

    POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...

  3. POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

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

  4. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  5. POJ 2739. Sum of Consecutive Prime Numbers

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

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

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

  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 小结

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

  9. poj 2739 Sum of Consecutive Prime Numbers 解题报告

    题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...

随机推荐

  1. 101. Symmetric Tree(判断二叉树是否对称)

      Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For ...

  2. 中高级PHP开发者应该掌握哪些技术?

    中级PHP程序员 1.Linux 能够流畅的使用Shell脚本来完成很多自动化的工作:awk/sed/perl 也操作的不错,能够完成很多文本处理和数据统计等工作:基本能够安装大 部分非特殊的Linu ...

  3. wait、notify为什么要放在同步代码块中

    等待方遵循的原则: 获取对象的锁,不满足条件就调用wait()方法,条件满足继续执行 通知方原则: 获取对象的锁,改变条件,然后notify 每个对象都有一个监视器锁,这个监视器锁的数据结构如下: w ...

  4. ABP官方文档翻译 1.1 介绍

    介绍 介绍 快速示例 其他 启动模板 如何使用 介绍 我们通常会根据不同的需求来创建不同的应用程序.但是对于一些通用相似的结构总是一遍又一遍的实现,至少在某种程度上是这样的.常见的通用模块如授权.验证 ...

  5. asp.net Mvc 使用uploadify 上传文件 HTTP 302 Error

    CSHTML代码 @{ if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { <input type=" ...

  6. LINUX SHELL 笔记 02: 变量初识

    https://www.shellscript.sh/variables1.html 变量是一个可操作(读.写)的内存块的名字. 尝试-1 创建一个变量: root@iZwz:~/labs# sh m ...

  7. centos7安装kvm环境采用网桥模式并创建虚拟机制作openstack需要的镜像

    初始环境的安装:centos7 mini iso镜像进行安装的系统 采用的环境是vm该软件,联网方式NAT模式下配置的静态ip(如何在NAT模式下配置静态ip参考之前的文章) 1.由于要安装kvm环境 ...

  8. 20145329《Java程序设计》第十周学习总结

    教材学习内容总结 网络编程 • 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的数据 1.网络概述 • 网络编程的实质:两个( ...

  9. 20145335郝昊《java程序设计》第4周学习总结

    20145335郝昊 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 何谓继承: 概念: 面向对象中,为避免多个类间重复定义共同行为.(简单说就是将相同的程序代码提升为父类. ...

  10. (转)C#调用C函数(DLL)传递参数问题

    备忘: 1.C函数参数为字符串char*.如果是入参,对应C#中string或StringBuilder:如果是出参对应C#中StringBuider: 2.C函数参数为结构体指针,需在C#中对应定义 ...