POJ 2739 Sum of Consecutive Prime Numbers

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

 

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
/*/
题意:
求连续素数和.
有多少种方法可以选取连续的素数,使这些数的和正好为n 思路:
1到10000的素数表打出来,然后直接尺取就可以了,很简单的一道题目。
/*/
#include"map"
#include"cmath"
#include"string"
#include"cstdio"
#include"vector"
#include"cstring"
#include"iostream"
#include"algorithm"
using namespace std;
typedef long long LL;
const int MX=1000005;
#define memset(x,y) memset(x,y,sizeof(x))
#define FK(x) cout<<"【"<<x<<"】"<<endl int vis[MX];
int prim[MX];
int ans[MX];
int main() {
int n,len=0,sum=0;
for(int i=2; i<=100; i++)
if(!vis[i])
for(int j=2; j<=10000; j++)
vis[j*i]=1;
for(int i=2; i<=10000; i++)
if(vis[i]==0) {
len++;
prim[len]=i;
}
for(int i=1; i<=len; i++) {
sum=0;
int j=i;
while(sum<=10000 && j<=1229) {
sum+=prim[j];
if(sum>10000)
break;
ans[sum]++;
j++;
}
}
while(~scanf("%d",&n)) {
if(!n)break;
printf("%d\n",ans[n]);
}
return 0;
}

  

ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法的更多相关文章

  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 素数 读题 难度:0

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

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

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

  4. POJ 2739. Sum of Consecutive Prime Numbers

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

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

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

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

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

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

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

  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 尺取法

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

随机推荐

  1. Asp.net窄屏页面 手机端新闻列表

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchNotice.a ...

  2. 如何减少JS的全局变量污染

    A,唯一变量 B,闭包

  3. 无废话ExtJs 入门教程七[登陆窗体Demo:Login]

    无废话ExtJs 入门教程七[登陆窗体Demo:Login] extjs技术交流,欢迎加群(201926085) 在这节我们通过前几节讲的内容做一个登陆页面,把前几节讲的内容贯穿一下. 1.代码如下: ...

  4. AngularJS讲义 - 作用域

    什么是作用域? Angular中作用域(scope)是模板以及工作的上下文环境,作用域中存放了应用模型和视图相关的回调行为.作用域是层次化结构的与相关联的DOM结构相对应.作用域可以观察表达式以及传播 ...

  5. oracle 10g\11g用imp导入数据的时候报错:ORA-01658: 无法为表空间 MAXDATA 中的段创建 INITIAL 区 错误解决

    备份文件是从11g中通过exp命令导出的,在10g下使用imp导入出现了上述错误,以为是低版本的不支持高版本的备份,于是使用11g测试,还是上面的问题. 其实是表空间大小不够的问题,下面是网上的解答: ...

  6. .NET Nancy 详解(一) 初识

    Nancy 是一个轻量级的,简单粗暴的framework用来构建基于HTTP的各种服务,兼容.Net和Mono.Nancy的整套设计理念是基于"super-duper-happy-path& ...

  7. angularjs 权威指南 版本 1.2.6

    1 $rootScope  run  : run 方法初始化全局的数据 ,只对全局作用域起作用 如$rootScope <script src="http://apps.bdimg.c ...

  8. [Eclipse] Eclipse字体问题解决

    背景: Eclipse的字体总感觉有点问题,其中中文字体太小,不方便查看,今天网上搜索了一下,解决了问题,记录下来: 解决办法: Window --> Preferences --> Ge ...

  9. vim用法小节

    1.把一个文件的内容全选复制到另一个文件 方案一: gg"*yG 然后另外一个vim "*p "*是系统剪贴板寄存器 方案二: 打开另一个文件,然后输入 :r filen ...

  10. Codeforces Round #370 (Div. 2) D. Memory and Scores DP

    D. Memory and Scores   Memory and his friend Lexa are competing to get higher score in one popular c ...