Anti-prime Sequences#630

Anti-prime Sequences

3 seconds
64 megabytes
Hard

Given a sequence of consecutive integers n, n+1, n+2, \ldots, m, an anti-prime sequence is a rearrangement of these integers such that each pair of adjacent numbers sums to a composite (non-prime) number. For example, if n = 1 and m = 10, one such anti-prime sequence is 1, 3, 5, 4, 2, 6, 9, 7, 8, 10. This sequence is also the lexicographically first anti-prime sequence for these numbers.

We can generalize the concept by defining the degree of an anti-prime sequence: in a degree anti-prime sequence, all contiguous subsequences of length 2, 3, \ldots, d must have their sums composite. The above sequence is a degree anti-prime sequence, but not degree , since the subsequence sums to . The lexicographically first degree anti-prime sequence for these numbers is 1, 3, 5, 4, 6, 2, 10, 8, 7, 9.

Input

Input consists of multiple test cases. Each test case is given as a line with three integers , , and . The constraints are 1 \leq n < m \leq 1000, 2 \leq d \leq 10. The line signals the end of input and should not be processed.

Output

For each input case, output in a single line the degree anti-prime sequence as a list of comma-separated numbers (do not insert spaces between numbers or split output across multiple lines). If more than one anti-prime sequence exists, output the lexicographically first. If there is no degree anti-prime sequence, output No anti-prime sequence exists.

Examples

Example 1

Loading
Loading