POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 25225 | Accepted: 13757 |
Description
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
Output
in the output.
Sample Input
- 2
- 3
- 17
- 41
- 20
- 666
- 12
- 53
- 0
Sample Output
- 1
- 1
- 2
- 3
- 0
- 0
- 1
- 2
Source
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <map>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <set>
- using namespace std;
- #define LL long long
- const int inf=0x3f3f3f3f;
- int n,m;
- int a[10005];
- bool isp(int x)
- {
- if(x<2)
- return 0;
- for(int i=2; i<=sqrt(x); i++)
- {
- if(x%i==0)
- return 0;
- }
- return 1;
- }
- int main()
- {
- int n;
- int cnt=0;
- for(int i=1; i<10005; i++)
- {
- if(isp(i))
- a[cnt++]=i;
- }
- while(~scanf("%d",&n)&&n)
- {
- int l=0,r=0,sum=0,cnt=0;
- while(1)
- {
- while(a[r]<=n&&sum<=n)
- {
- sum+=a[r++];
- if(sum==n)
- cnt++;
- }
- if(sum<=n) break;
- sum-=a[l++];
- if(sum==n) cnt++;
- }
- printf("%d\n",cnt);
- }
- return 0;
- }
POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏的更多相关文章
- Hdu1016 Prime Ring Problem(DFS) 2016-05-06 14:27 329人阅读 评论(0) 收藏
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- POJ2739 - Sum of Consecutive Prime Numbers(素数问题)
题目大意 给定N,要求你计算用连续的素数的和能够组成N的种数 题解 先筛选出素数,然后暴力判断即可... 代码: #include<iostream> #include<cstrin ...
- Prime Path 分类: 搜索 POJ 2015-08-09 16:21 4人阅读 评论(0) 收藏
Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14091 Accepted: 7959 Descripti ...
- POJ2566 Bound Found 2017-05-25 20:05 32人阅读 评论(0) 收藏
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4056 Accepted: 1249 Spe ...
- POJ2739 Sum of Consecutive Prime Numbers 确定某个数以内的所有素数
参考:https://www.cnblogs.com/baozou/articles/4481191.html #include <iostream> #include <cstdi ...
- hdu 1231, dp ,maximum consecutive sum of integers, find the boundaries, possibly all negative, C++ 分类: hdoj 2015-07-12 03:24 87人阅读 评论(0) 收藏
the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is o ...
- Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏
Self Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22101 Accepted: 12429 De ...
随机推荐
- Junit4知识梳理
一.junit官网 junit4:http://junit.org/junit4/ junit5:http://junit.org/junit5/ 二.github junit4: https://g ...
- nginx日志
相关知识可参考文章:nginx日志格式及自定义日志配置 1.查看nginx的log配置 1)vim /etc/nginx/nginx.conf 打开为 user nginx;worker_proces ...
- 关于ip包长度
http://blog.csdn.net/naturebe/article/details/6712153 这篇文章总结的不错,转自:http://hi.baidu.com/to_wait/blog/ ...
- BZOJ1059或洛谷1129 [ZJOI2007]矩阵游戏
BZOJ原题链接 洛谷原题链接 通过手算几组例子后,很容易发现,同一列的\(1\)永远在这一列,且这些\(1\)有且仅有一个能产生贡献,行同理. 所以我们可以只考虑交换列,使得每一行都能匹配一个\(1 ...
- QueryRunner类的八种结果处理集
package cn.jy.demo; import java.sql.Connection; import java.sql.SQLException; import java.util.List; ...
- JDK8集合类源码解析 - HashSet
HashSet 特点:不允许放入重复元素 查看源码,发现HashSet是基于HashMap来实现的,对HashMap做了一次“封装”. private transient HashMap<E,O ...
- Java学习笔记:23种设计模式
设计模式(Design pattern)的定义: In software engineering, a software design pattern is a general, reusable s ...
- mybatis-mysql类型映射
JDBC Type Java Type CHAR String VARCHAR String LONGVARCHAR String NUMERIC java.math.BigDecimal DECIM ...
- 【Web】CSS实现绝对定位元素水平垂直居中
网页中常常需用让绝对定位元素水平垂直居中,下面介绍2种方法: 一 元素宽度未知 <!DOCTYPE html> <html lang="en"> <h ...
- Android Makefile中是 如何识别 TARGET_PRODUCT 的
http://blog.csdn.net/stevenliyong/article/details/5285334 今天有时间小看一下Android 的Makefile, 终于稍有明白Android ...