sicily 1259. Sum of Consecutive Primes
来源:互联网 发布:艾科特餐饮软件 编辑:程序博客网 时间:2024/06/05 18:29
1259. Sum of Consecutive Primes
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
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
题目分析
求给定数可以产生几种由连续素数构造的方法
每个素数只能用一次且连续
考察筛法求素数
#include <stdio.h>#include <memory.h>bool isprime[10001];void init() { memset(isprime, true, sizeof(isprime)); for (int i = 2; i <= 10000; ++i) if (isprime[i]) { for (int j = i+i; j <= 10000; j += i) isprime[j] = false; }}int main(){ init(); int num; while (scanf("%d", &num)) { if (num == 0) break; int count = 0; for (int i = 2; i <= num; ++i) { if (isprime[i]) { int temp = num; int index = i; while (true) { if (isprime[index]) temp -= index; if (temp == 0) { ++count; break; } else if (temp < 0) break; ++index; } } } printf("%d\n", count); }}
- Sicily 1259. Sum of Consecutive Primes
- Sicily 1259. Sum of Consecutive Primes
- sicily 1259. Sum of Consecutive Primes
- Sicily 1259. Sum of Consecutive Primes |
- 1259. Sum of Consecutive Primes
- Sum of Consecutive Primes
- Sum of Consecutive Primes
- SOJ 1259. Sum of Consecutive Primes
- sicily1259 Sum of Consecutive Primes
- <OJ_Sicily>Sum of Consecutive Primes
- 1259. Sum of Consecutive Primes(连续素数求和)
- Sum of Different Primes
- UVa1213 Sum of Different Primes
- poj3132 Sum of Different Primes
- poj3132 Sum of Different Primes
- Sum of Different Primes UVA
- WOJ1274-Sum of Different Primes
- Sum of Different Primes UVA
- Eclipse CDT 代码首次编译通过,第二次编译提示error: ld returned 1 exit status
- JAVA设计模式(21) —<行为型>访问者模式(Visitor)
- 10009---JavaWeb基础--GenericServlet
- unity Instantiate后立刻SetActive(false)会执行的方法
- c++ 实验探究之数组
- sicily 1259. Sum of Consecutive Primes
- 自定义泛型JAVA_116-118
- UI基础-事件处理
- 安卓 URL编码 和解码注意事项
- HDOJ 题目4284 A Famous Stone Collector(组合数学)
- ListView的优化
- 智能指针sp/wp使用
- MySQL存储引擎总结
- web开发中常用的几种统计图使用