博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
阅读量:4307 次
发布时间:2019-06-06

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

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

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 题目分析:给你一个数,如果这个数能够表示成几个连续的素数相加的形式,请问有多少种这样的形式。  例如:41=2+3+5+7+11+13       41=11+13+17       41=41   共有3种 像这种7+13=20 或者 3+5+5+7=20  这些都是不合法的。 算法分析:数据范围不大,先将1000以内的素数存在一个数组里,两层循环进行暴力枚举         外层循环控制最小的素数累加和的起点数,从它开始一直累加下去直到>=输入数。         如果累加和==n,计数器++,最后输出结果。 代码如下:
#include 
#include
#include
#include
#include
using namespace std;int prime[2000], total=0;bool isprime(int k ){ for(int i=0; i
=prime[i]; i++) { int cnt=0; for(j=i; j

 

 

转载于:https://www.cnblogs.com/yspworld/p/4242050.html

你可能感兴趣的文章
Redis项目实战--应用及理论(一)--redis基础
查看>>
Redis项目实战---应用及理论(二)---Redis集群原理
查看>>
VMware vSphere API开发(一)---vSphere 体系核心概念
查看>>
java String 的比较
查看>>
将String数字字符转为整型
查看>>
【转】 Java中equals和==的区别
查看>>
idea导入maven项目时需要注意
查看>>
nginx部署前端项目的一些配置【刚入门】
查看>>
java 日期格式化 将String日期重新格式化成String型【转】
查看>>
Linux下python安装升级详细步骤 | Python2 升级 Python3
查看>>
阿里云CentOS安装图形化界面
查看>>
SpringBoot nohup启动
查看>>
PHP pclzip.php 解压中文乱码
查看>>
Jenkins安装 maven插件
查看>>
数学好玩 沛沛猜想
查看>>
银联号
查看>>
银行开发平台
查看>>
Linux网络配置
查看>>
Linux开机、重启、和用户登录注销
查看>>
Linux运行级别
查看>>