POJ 2739Sum of consecutive Prime NumbersTime
limit:1000MS
Memory Limit:65536KB
64bit IO Format:%lld &%llu< /c8>
Description
Some positive integers can be is represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer has? For example, the integer is has a representations 5 + 7 + one + + + 53. The integer 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 has no such representations. Note that Summands must is consecutive prime
Numbers, so neither 7 + or 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program this reports the number of representations for the given positive integer.
Input
The input is a sequence of positive integers, each with a separate line. The integers is between 2 and ten, inclusive. The end of the input is indicated by a zero.
Output
The output should is composed of lines each corresponding to a 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 Nu Mbers. No other characters should is inserted in the output.
Sample Input
2317412066612530
Sample Output
11230012
/* /test Instructions:
The number of consecutive primes and.
There are several ways to select successive primes to make these numbers exactly n-thinking:
1 to 10000 of the prime number of the table, and then the direct ruler to take it, a very simple topic. /*/
#include "map" #include "Cmath" #include "string" #include "Cstdio" #include "vector" #include "CString" #include "iostream "#include" algorithm "using namespace Std;typedef long long ll;const int mx=1000005; #define MEMSET (x, y) memset (x,y,sizeof (x)) #define FK (x) cout<< "" "<<x<<" "" <<endlint vis[mx];int prim[mx];int ans[mx];int main () {int n, len=0,sum=0;for (int i=2; i<=100; i++) if (!vis[i]) for (int j=2; j<=10000; j + +) vis[j*i]=1;for (int i=2; i<=10000; i + +) if (vis[i]==0) {len++;p rim[len]=i;} for (int i=1; i<=len; i++) {sum=0;int j=i;while (sum<=10000 && j<=1229) {sum+=prim[j];if (sum> 10000) break;ans[sum]++;j++;}} while (~SCANF ("%d", &n)) {if (!n) break;printf ("%d\n", Ans[n]);} return 0;}
Acm:poj 2739 Sum of consecutive prime numbers-prime numbers-scale extraction