Cow-abunga!
InterviewTime limit1sMemory limit1024 MB
Given at most 9 cow weights, choose M of them and print every prime number that appears as a subset sum, in increasing order.
- Level
Medium4 of 10
- Topics
- Brute force, Combinatorics, Number theory, Sorting
- Solved
- No attempts yet
Problem
The winners of the last barn raffle have been announced. The cows that won the raffle were so happy they felt like flying, and then they actually flew into the sky. But after that, the cows could no longer fly. Then one day they realized that a bee sting lets them fly for a short while. Once this fact spread, the cows began flying freely through the sky again.
As the cows flew and cow traffic accidents became frequent, Farmer John restricted the cows' flying. The cows protested, but their protests were not accepted.
There are cows on the farm. Farmer John plans to select cows so that the sum of their weights is a prime number. Print every weight sum that can result from selecting cows according to Farmer John's plan.
Input
The first line gives the number of cows on the farm and the number of cows to select .
The second line gives the weights of the cows .
Output
Print, in increasing order, every prime number that can be made as the sum of the weights of cows. If no such case exists, print .