Sum of Distinct Primes
Time limit1sMemory limit128 MB
Count subsets of k distinct primes summing to n, using dynamic programming over sieve-generated primes up to 1120.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Math, Number theory
- Solved
- No attempts yet
Problem
Every positive integer can be written as a sum of distinct primes. Given two integers and , write a program that counts the number of ways to write as a sum of distinct primes. Two representations that differ only in the order of the summands (for example and ) are considered the same and counted once.
For example, when and there are 2 ways: and . When and there are 3 ways: , , and . When and there is 1 way: . When and the answer is 0 because 1 is not prime. Likewise, no two distinct primes sum to 4, so the answer for , is also 0.
Input
The first line contains the number of test cases . Each test case is a single line containing two integers and separated by a space. (, )
Output
For each test case, print the number of ways on its own line. The answer is always less than .