UVA-1213Sum of Different Primes
Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Submit Status Description A positive integer may is expressed as a sum of different prime numbers (primes), in one-or another. Given-positive integers n andK, you should count the number of ways to express n as a sum o F k different primes. Here, the ways is considered to being the same if they sum up the same set of the primes. For example, 8 can is expressed as 3 + 5 and 5 + 3 But they is not distinguished. WhenNandkIs -and3Respectively, the answer is both because there is and sets{2, 3, +}and{2, 5, +}Whose sums is equal to -. There is no other sets of three primes, sum up to -. For N =and k = 2, the answer is three, because there is three sets{5, +},{7, +}and{One, one}. For N = 2and k = 1, the answer is one, because there are only one set{2}Whose sum is2. For N = 1and k = 1, the answer is zero. As1Isn't a prime, you shouldn ' t count{1}. For N = 4and k = 2, the answer is zero, because there was no sets of the different primes whose sums are4. Your job is to write a program this reports the number of such ways for the given n and K. InputThe input is a sequence of datasets followed by a line containing, and zeros separated by a space. A DataSet is a line containing the positive integers n and K separated by a space. Assume that n1120 and k. OutputThe output should is composed of lines, each corresponding to an input dataset. An output line should contain one non-negative integer indicating the number of ways for n and K Specifi Ed in the corresponding dataset. Assume that it's less than 231. Sample Input24 3 24 2 2 1 1 1 4 2 18 3 17 1 17 3 17 4 100 5 1000 10 1120 14 0 0 Sample Output2 3 1 0 0 2 1 0 1 55 200102899 2079324314
Source Root:: AOAPC ii:beginning algorithm Contests (Second Edition) (Rujia Liu):: Chapter 10. Maths:: Exercises Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: Problem Solving Paradigms:: Dynamic Programming:: 0-1 knapsack (subset Sum) Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: Problem Solvi Ng Paradigms:: Dynamic Programming:: 0-1 knapsack (subset Sum)Submit Status |