
The first line of the input contains a single integer 'T', representing the number of test cases.
The first line of each test case contains 2 space-separated integers, representing the integers ‘N’ and ‘K’.
For each test case, print the 1, if the number can be formed with the sum of ‘K’ prime numbers, else print 0.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N, K <= 3*10^3
Time Limit: 1 sec
The basic idea is to check for all the possible combinations of forming ‘N’ by the sum of ‘K’ prime numbers.
Here is the algorithm :
isPrime(N)
The idea is to use Goldbach’s Conjecture which states that every even integer greater than 2 can be expressed as the sum of two prime numbers.
Example:
44 = 41 + 3
38 = 31 + 7
There are three conditions we need to solve.
Example: Let ‘N’ be 35 and ‘K’ be 5. Then it can be written as 2, 2, …, ‘K’ - 3 times., i.e., 35 can be written as 2, 2, 3, 5, 23.
Here is the algorithm :