A - Sum of Consecutive Prime Numbers
来源:互联网 发布:windows组件中没有ie 编辑:程序博客网 时间:2024/05/01 05:54
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.
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 <iostream>int main(){bool leap(int n);int next(int n);int checkNum;std::cin>>checkNum;while (checkNum!=0){int count=0;if (leap(checkNum))count++;for (int i=2;i<=checkNum/2;i=next(i)){int sum=i;for (int j=next(i);j<=checkNum;j=next(j)){sum+=j;if (sum==checkNum)count++;else if (sum<=checkNum)continue;else if (sum>checkNum)break;}}std::cout<<count<<std::endl;std::cin>>checkNum;}return 0;}bool leap(int n){bool flag=true;int i;for (i=2;i*i<=n;i++)if (n%i==0)flag=false;return flag;}int next(int n){bool flag=true;while (flag){n+=1;if (leap(n))flag=false;}return n;}
- A - Sum of Consecutive Prime Numbers
- A - Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers pku 2739
- POJ2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- poj 2739 Sum of Consecutive Prime Numbers
- POJ 2739 Sum of Consecutive Prime Numbers
- java笔记 集合总结
- 浏览器数据包截获Man-in-the-browser
- 一个人IT民工的这周的牢骚话(1)
- 现代通信之我见
- 工厂方法设计模式
- A - Sum of Consecutive Prime Numbers
- 工厂方法设计模式
- 状态机编程
- Ahui Writes Word hdu3732 多重背包
- 第一次开发分享的经验教训
- VMware网络设置(超级好)
- 但做实事,莫问前程
- 如何扩展Orchard
- 数组求和问题