问题 J: Permutation and Primes

内存限制:512 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:9 通过:5

题目描述

链接:https://ac.nowcoder.com/acm/contest/57362/J
来源:牛客网
Given nnn, you should construct a permutation PPP of {1,2,…,n}\{1, 2, \ldots, n\}{1,2,,n} satisfying that for all 1≤i<n1 \le i < n1i<n, either Pi+Pi+1P_i + P_{i+1}Pi+Pi+1 is an odd prime or ∣Pi−Pi+1∣|P_i - P_{i+1}|PiPi+1 is an odd prime.

If multiple solutions exist, print any of them. If no solution, print "-1" in one line.

输入格式

The first line contains one integer TTT (1≤T≤1051\le T \le 10^51T105), denoting the number of test cases.
For each test case, input only one line containing one integer nnn (2≤n≤1052\le n \le 10^52n105).
It is guaranteed that the sum of nnn among all test cases in one test file does not exceed 10610^6106.


输出格式

For each test case:

If solution exists, print one line containing nnn integers P1,P2,…,PnP_1, P_2, \ldots, P_nP1,P2,,Pn (1≤Pi≤n1 \le P_i \le n1Pin, ∀1≤i<j≤n,Pi≠Pj\forall \, 1 \le i < j \le n, P_i \neq P_j1i<jn,Pi=Pj), denoting the permutation you construct.
If no solution, print "-1" in one line.

输入样例 复制

2
3
5

输出样例 复制

1 2 3
5 2 1 4 3

数据范围与提示

In the first test case, 1+2=3,2+3=51 + 2 = 3, 2 + 3 = 51+2=3,2+3=5 are odd primes.
In the second test case, ∣5−2∣=3,2+1=3,∣1−4∣=3,4+3=7|5 - 2| = 3, 2 + 1 = 3, |1 - 4| = 3, 4 + 3 = 752=3,2+1=3,14=3,4+3=7 are odd primes.