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 ...
随机推荐
- python添加fluent日志记录-aop
python添加fluent日志,aop实现 1.配置fluent相关信息 fluent_config.ini fluent_config.ini [fluent.aop] #is support f ...
- 8Q - 献给杭电五十周年校庆的礼物
我不能参赛,就送给学校一个DOOM III球形大蛋糕吧.等一等,吃蛋糕之前先考大家一个问题:如果校长大人在蛋糕上切了N刀(校长刀法极好,每一刀都是一个绝对的平面),最多可以把这个球形蛋糕切成几块呢? ...
- 日期控件 DatePicker 在ie8不能用
过个年,日期控件DatePicker在ie8下突然不能用了,程序也没升级,很是奇怪. 把ie8的“禁用脚本调试”去掉,再次运行,发现提示有脚本错误. 想着可能是兼容性问题,于是把兼容性视图打开运行,还 ...
- win7系统 无线上网卡 共享网络,设置成wifi热点
给家人买了一个新的智能手机,用的移动神州行套餐,没有开通3G,想更新一些应用软件,于是想到能不能用电脑上的无线上网卡. 在网上找到了一方法,试了一下,还真是可以. 步骤如下: 用无线上网卡拨号上网,并 ...
- C# iframe session 丢失
在页面A中使用iframe引用另一站点页面B,但页面B上面的session总是丢失,百度了一下,不用改程序,直接在iis里面操作,解决方法如下 1.打开IIS管理器 inetmgr 2.选择被嵌入if ...
- IDEA 的基本介绍
1.工具界面 (1)工程下的 src 类似于 Eclipse 下的 src 目录, 用于存放代码. (2)工程下的.idea 和 project01.iml 文件都是 IDEA 工程特有的.类似于 E ...
- Delphi XE2有什么新功能
具体内容见PDF Delphi XE2有什么新功能Delphi XE2提供(offers)了令人兴奋(exciting)的新功能,让您能够建立高度可视化的,在Windows,Mac和iOS上的业务应用 ...
- JavaScript调用wcf服务,并且处理返回的字典集合
1.第一步创建wcf服务的方法 using System;using System.Collections.Generic;using System.Linq;using System.Runtime ...
- js处理img标签加载图片失败,显示默认图片
1.第一种方法: 如果已经引入了jquery插件,就很好办.没有的话,如果实在需要,可以附上代码: script(type='text/javascript', src="http://aj ...
- 算法题思路总结和leecode继续历程
2018-05-03 刷了牛客网的题目:总结思路(总的思路跟数学一样就是化简和转化) 具体启发点: 1.对数据进行预处理排序的思想:比如8皇后问题 2.对一个数组元素进行比较的操作,如果复杂,可以试试 ...