poj 2739 Sum of Consecutive Prime Numbers 小结
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
integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.
#include<stdio.h>
#include<cmath>
using namespace std;
long i,j,a[1230],n;
bool p(long k)
{
for (long i=2;i<=trunc(sqrt(k));i++)
if (k%i==0) return false;
return true;
}
int main()
{
for (i=1;i<=1229;i++) a[i]=0;
long cnt=1;a[cnt]=2;
for (i=3;i<=10000;i++)
if (p(i)){cnt++;a[cnt]=a[cnt-1]+i;}
scanf("%ld",&n);
while (n!=0)
{
long ans=0;
for (i=1;i<=cnt;i++)
for (j=i;j<=cnt;j++)
{
if (a[j]-a[i-1]==n) ans++;
else if (a[j]-a[i-1]>n) break;
}
printf("%ld\n",ans);
scanf("%ld",&n);
}
return 0;
}
poj 2739 Sum of Consecutive Prime Numbers 小结的更多相关文章
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- poj 2739 Sum of Consecutive Prime Numbers 解题报告
题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...
随机推荐
- 开涛spring3(6.3) - AOP 之 6.3 基于Schema的AOP
6.3 基于Schema的AOP 基于Schema的AOP从Spring2.0之后通过“aop”命名空间来定义切面.切入点及声明通知. 在Spring配置文件中,所以AOP相关定义必须放在<a ...
- R – GPU Programming for All with ‘gpuR’
INTRODUCTION GPUs (Graphic Processing Units) have become much more popular in recent years for compu ...
- Java如何转换protobuf-net中的bcl.DateTime对象
一.定义DateTime Message 参考文档:https://github.com/mgravell/protobuf-net/blob/master/src/Tools/bcl.proto m ...
- 简单bmp图片处理工具——python实现
预备实现功能: 1.读取bmp文件 2.保存bmp文件 3.对bmp图片进行放大.缩小 4.对bmp图片进行灰度化 5.对bmp图片进行旋转 bmp文件格式非常简单,对于我这种初学者来说减少了不少不必 ...
- cs6安装
[按下面步骤操作 无需序列号] ·打上补丁 永远无需序列号 (现在网上没什么能用的序列号) ·1双击CS软件安装,选择试用 ·2创建ID 输入自己邮箱和密码,姓名可以随意输入 ·3安装完成后 运行一次 ...
- React-Native集成到已有项目中的总结
安装Python 从官网下载并安装python 2.7.x(3.x版本不行) 安装node.js 从官网下载node.js的官方V6.X.X版本或更高版本.安装完成后检测是否安装成功:node -v ...
- lucene全文搜索之四:创建索引搜索器、6种文档搜索器实现以及搜索结果分析(结合IKAnalyzer分词器的搜索器)基于lucene5.5.3
前言: 前面几章已经很详细的讲解了如何创建索引器对索引进行增删查(没有更新操作).如何管理索引目录以及如何使用分词器,上一章讲解了如何生成索引字段和创建索引文档,并把创建的索引文档保存到索引目录,到这 ...
- Java使用条件语句和循环结构确定控制流
与任何程序设计语言一样,Java使用条件语句和循环结构确定控制流.本文将简单讲解条件.循环和switch. 一.块作用域 块(block),即复合语句.是指由一对大括号括起来的若干条简单的Java语句 ...
- 聊聊RocksDB Compact
| 导语 对于 LevelCompact 策略,RocksDB会根据每一层不同的策略计算出CompactScore,根据CompactScore大小来决定那一层将会优先进行Compact,然后选择Le ...
- python web -- django
一. 安装 django $ pip install django (env)$ python >> import django >> django.VERSION >& ...