This page is still under construction.

Parts of this page are still being built. What you see may change.

Prime-Free Sequence

Time limit1sMemory limit128 MB

Summary
Find the lexicographically smallest permutation of n..m where sums of any 2 to d consecutive numbers are all non-prime, or report none.
Level

Medium7 of 10

Topics
Backtracking, DFS, Number theory, Greedy
Solved
No attempts yet

Problem

Consider the sequence of consecutive integers n,n+1,n+2,…,mn, n+1, n+2, \dots, m from nn to mm. By rearranging these numbers appropriately, you can make the sum of every two adjacent numbers non-prime; a sequence arranged this way is called a prime-free sequence.

For example, when n=1n = 1 and m=10m = 10, the arrangement 1, 3, 5, 4, 2, 6, 9, 7, 8, 10 is one prime-free sequence, and it is the lexicographically smallest among all of them.

Extending this idea, a dd-th order prime-free sequence is a sequence in which the sum of every 2,3,…,d2, 3, \dots, d consecutive numbers is non-prime. The sequence above is a 22nd order prime-free sequence, because the sum of each pair of adjacent numbers is non-prime. It is not a 33rd order prime-free sequence, however, because the three consecutive numbers 5, 4, 2 sum to 11, which is prime. For n=1n = 1 and m=10m = 10, the lexicographically smallest 33rd order prime-free sequence is 1, 3, 5, 4, 6, 2, 10, 8, 7, 9.

Given nn, mm, and dd, write a program that finds the lexicographically smallest dd-th order prime-free sequence.

Input

The input consists of several test cases. Each test case is a single line containing three integers nn, mm, and dd separated by spaces, satisfying 1≤n<m≤10001 \le n < m \le 1000 and 2≤d≤102 \le d \le 10.

The last line of the input contains 0 0 00\ 0\ 0 and must not be processed.

Output

For each test case, print the dd-th order prime-free sequence on one line, with the numbers separated by commas (,). If more than one such sequence exists, print the lexicographically smallest one (the sequence whose first number is smallest; if tied, whose second number is smallest; and so on).

If no dd-th order prime-free sequence exists, print No anti-prime sequence exists.

Examples1

  1. Example 1

    Input
    1 10 2
    1 10 3
    1 10 5
    40 60 7
    0 0 0
    
    Expected output
    1,3,5,4,2,6,9,7,8,10
    1,3,5,4,6,2,10,8,7,9
    No anti-prime sequence exists.
    40,41,43,42,44,46,45,47,48,50,55,53,52,60,56,49,51,59,58,57,54