Poj 2739 sum of consecutive prime numbers

Source: Internet
Author: User

Sum of consecutive prime numbers

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 shoshould be composed of lines each corresponding to an input line should t the last zero. an output line des the number of representations for the input Integer as the sum of one or more consecutive prime numbers. no other characters shoshould be inserted in the output.

Sample Input

2317412066612530

Sample output

11230012

Sincere questions !!!

The AC code is as follows:


/// Fill in the table with water over 16 Ms 164 K # include <iostream> # include <cstdio> # include <cstring> # define M 10005 using namespace STD; int prime [m]; int TT = 0; void ISP () {int I, j; prime [TT ++] = 2; for (I = 3; I <m; I ++ = 2) {int flag = 1; for (j = 2; j * j <= I; j ++) {if (I % J = 0) {flag = 0; break ;}} if (FLAG) prime [TT ++] = I;} return ;}int main () {ISP (); int N, I, j; int sum; while (~ Scanf ("% d", & N) {int ans = 0; for (I = 0; I <tt; I ++) {If (prime [I]> N) break; sum = 0; For (j = I; j <tt; j ++) {sum + = prime [J]; if (sum = N) ans ++; If (sum> N) Break ;}} printf ("% d \ n", ANS) ;}return 0 ;}


Poj 2739 sum of consecutive prime numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.