发布时间: 2017年12月10日 22:14 最后更新: 2017年12月10日 22:18 时间限制: 1000ms 内存限制: 512M SPJ
The 2017 FDU-ICPC contest has started, but Gromah is stuck by a question, so Gromah wants to pick a lucky permutation and output it directly. Gromah each time will randomly write down two integers n and k and then find a lucky permutation of 1~n . From Gromah’s perspective, a lucky permutation is such permutation p that for every successive interval of length k, the sum is always a composite number.
Altogether Gromah writes down T pairs of n and k. Now Gromah wants to know whether there exists a lucky permutation for each pair of n and k. If any, print one of them, otherwise print “-1” (without the quotes).
The first line contains a integer T(T<=20), denoting the number of test cases.
For the following T lines, each line contains two integers n and k(1<=k<=n<=1000) denoting a test case.
For each test case, print n integers in a line indicating a lucky permutation or print -1 indicating there is no solution.
2 4 3 4 2
2 4 3 1 -1
For the first test case, the sum of the interval [1,3] is 2+4+3=9 and the sum of the interval [2,4] is 4+3+1=8. 8 and 9 are both composite numbers.
For the second test case, there is no lucky permutation.