P21141 [CodeChef] SUMPERM
普及-
题目描述

You are given an integer N. Your task is to generate a permutation P of size N, such that:

For all (1< i≤ $N), \sum_{j = 1}^{i} P_{j}$ is not divisible by i.
In other words, the sum of prefix of length i (i> 1) should not be divisible by i.

In case multiple such permutations exist, print any. If no such permutation exists, print -1 instead.

Note that a permutation of size N contains all integers from 1 to N exactly once.

------ Input Format ------

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists a single integer N — the size of the permutation.

------ Output Format ------

For each test case, output on a new line, N space separated integers, denoting the required permutation.

In case multiple such permutations exist, print any. If no such permutation exists, print -1 instead.

------ Constraints ------

$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 10^{4}$
- The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$.

----- Sample Input 1 ------
3
4
6
7

----- Sample Output 1 ------
3 4 1 2
1 2 4 6 3 5
-1

----- explanation 1 ------
Test case $1$: A possible permutation satisfying the given conditions is $P = [3, 4, 1, 2]$.
- For $i = 2$: The prefix sum is $3+4=7$, which is not divisible by $2$.
- For $i = 3$: The prefix sum is $3+4+1=8$, which is not divisible by $3$.
- For $i = 4$: The prefix sum is $3+4+1+2=10$, which is not divisible by $4$.

Test case $2$: A possible permutation satisfying the given conditions is $P = [1, 2, 4, 6, 3, 5]$.
- For $i = 2$: The prefix sum is $1+2=3$, which is not divisible by $2$.
- For $i = 3$: The prefix sum is $1+2+4=7$, which is not divisible by $3$.
- For $i = 4$: The prefix sum is $1+2+4+6=13$, which is not divisible by $4$.
- For $i = 5$: The prefix sum is $1+2+4+6+3=16$, which is not divisible by $5$.
- For $i = 6$: The prefix sum is $1+2+4+6+3+5=21$, which is not divisible by $6$.

Test case $3$: It can be proven that no permutation of length $7$ satisfies the given conditions.

输入格式

见题面

输出格式

见题面

样例输入
3 4 6 7
样例输出
3 4 1 2 1 2 4 6 3 5 -1