eolymp
bolt
Try our new interface for solving problems
Problems

Sum of Different Primes

Sum of Different Primes

A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers \textbf{n} and \textbf{k}, you should count the number of ways to express \textbf{n} as a sum of \textbf{k} different primes. Here, two ways are considered to be the same if they sum up the same set of the primes. For example, \textbf{8} can be expressed as \textbf{3 + 5} and \textbf{5 + 3} but they are not distinguished. When \textbf{n} and \textbf{k} are \textbf{24} and \textbf{3} respectively, the answer is two because there are two sets \{\textbf{2}, \textbf{3}, \textbf{19}\} and \{\textbf{2}, \textbf{5}, \textbf{17}\} whose sums are equal to \textbf{24}. There are no other sets of three primes that sum up to \textbf{24}. For \textbf{n = 24} and \textbf{k = 2}, the answer is three, because there are three sets \{\textbf{5}, \textbf{19}\}, \{\textbf{7}, \textbf{17}\} and \{\textbf{11}, \textbf{13}\}. For \textbf{n = 2} and \textbf{k = 1}, the answer is one, because there is only one set \{\textbf{2}\} whose sum is \textbf{2}. For \textbf{n = 1} and \textbf{k = 1}, the answer is zero. As \textbf{1} is not a prime, you shouldn't count \{\textbf{1}\}. For \textbf{n = 4} and \textbf{k = 2}, the answer is zero, because there are no sets of two different primes whose sums are \textbf{4}. Your job is to write a program that reports the number of such ways for the given \textbf{n} and \textbf{k}. \InputFile Each line gives one dataset containing two positive integers \textbf{n} (\textbf{n} ≤ \textbf{1120}) and \textbf{k} (\textbf{k} ≤ \textbf{14}) separated by a space. The last line contains two zeros and is not processed. \OutputFile For each test case print in a separate line the number of ways to express \textbf{n} as a sum of \textbf{k} different primes. You may assume that each answer is less than \textbf{2^31}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
24 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
Output example #1
2
3
1
0
0
2
1
0
1
55
200102899
2079324314