博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ Sum of Consecutive Prime Numbers
阅读量:6364 次
发布时间:2019-06-23

本文共 1763 字,大约阅读时间需要 5 分钟。

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

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

2317412066612530

Sample Output

11230012

Source

 
打个素数表就行了
 
View Code
#include
int prime[1500] ,count = 0;void getPrime(){ int f[11000] = {
0} ; for(int i=2;i<=10009;i++){ if(!f[i]){ prime[count++] = i ; for(int j=i;j<=10009;j+=i) f[j] = 1; } }}int main(){ getPrime() ; int n ; while(scanf("%d",&n) && n){ int ans = 0; for(int i=0;i

 

转载于:https://www.cnblogs.com/jun930123/archive/2012/08/16/2641039.html

你可能感兴趣的文章
把HDFS里的json数据转换成csv格式
查看>>
WEEX-EROS | 集成并使用 bindingx
查看>>
Spring5源码解析-Spring中的异步和计划任务
查看>>
广州牵引力来告诉你学编程先学什么语言好?
查看>>
广州牵引力总结初学者怎样学好UI设计?
查看>>
使用Metrics方法级远程监控Java程序
查看>>
Spring核心系列之Bean的生命周期
查看>>
VasSonic源码之并行加载
查看>>
小程序 LRU 存储设计
查看>>
Android 多线程之阻塞队列
查看>>
[译] 关于 Angular 依赖注入你需要知道的
查看>>
Haskell 在 macOS 下的环境搭建
查看>>
适配mpvue平台的的微信小程序日历组件mpvue-calendar
查看>>
【Linux学习】 Redis常用的一些指令
查看>>
Spring Cloud 中使用Feign解决参数注解无法继承的问题
查看>>
数据迁移方案 + Elasticsearch在综合搜索列表实现
查看>>
干货 | 分分钟教你用Python创建一个区块链
查看>>
Angular开发实践(八): 使用ng-content进行组件内容投射
查看>>
django rest framework mixins小结
查看>>
<<iOS 与OS X多线程和内存管理>>笔记:Blocks
查看>>