Weaker Goldbach
Time limit1sMemory limit128 MB
For each given integer, write it as a sum of distinct odd primes using the fewest terms, breaking ties by the lexicographically smallest ascending list.
- Level
Medium7 of 10
- Topics
- Number theory, Greedy, Math, Brute force
- Solved
- No attempts yet
Problem
In 1742 Christian Goldbach wrote to Leonhard Euler that, in his opinion, every integer is a sum of three primes. (A prime is an integer whose only positive divisors are and .) Euler replied that this claim is equivalent to the statement that every even number is a sum of two primes. Neither remark brought them closer to the underlying question: is it actually true? Today the statement has been verified for numbers up to , and much more is known, yet the conjecture is still open.
We will not try to settle it. Instead we solve a more modest problem that relies on the following fact: every integer can be written as a sum of distinct odd primes.
Given several integers, decompose each of them into a sum of distinct odd primes.
Because a number can usually be split in many ways, we ask for a single well-defined answer: use as few primes as possible, and if several decompositions attain that minimum, output the lexicographically smallest one (compare the two ascending lists element by element).
Input
The first line contains one positive integer (). Each of the next lines contains one integer from the interval .
Output
For each integer , print its decomposition on two lines. The first line contains one integer , the number of primes in the decomposition. The second line contains those distinct odd primes in ascending order, separated by single spaces; their sum equals .
Among all decompositions of into distinct odd primes, output the one that uses the fewest primes; if several use that same minimum number, output the lexicographically smallest such list. Print the decompositions in the same order as the integers in the input.