# Prefix Permutation CodeChef Solution

### We Are Discuss About CODECHEF SOLUTION

Prefix Permutation CodeChef Solution

## Prefix Permutation CodeChef Solution ## Problem

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

• For all (1<�≤�)∑�=1��� is not divisible by .
In other words, the sum of prefix of length  (�>1) should not be divisible by .

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

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

### Input Format

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

### Output Format

For each test case, output on a new line,  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≤�≤1000
• 2≤�≤104
• The sum of  over all test cases won’t exceed 2⋅105.

### Sample 1:

Input

Output

3
4
6
7

3 4 1 2
1 2 4 6 3 5
-1

### Explanation:

Test case 1: A possible permutation satisfying the given conditions is �=[3,4,1,2].

• For �=2: The prefix sum is 3+4=7, which is not divisible by 2.
• For �=3: The prefix sum is 3+4+1=8, which is not divisible by 3.
• For �=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 �=[1,2,4,6,3,5].

• For �=2: The prefix sum is 1+2=3, which is not divisible by 2.
• For �=3: The prefix sum is 1+2+4=7, which is not divisible by 3.
• For �=4: The prefix sum is 1+2+4+6=13, which is not divisible by 4.
• For �=5: The prefix sum is 1+2+4+6+3=16, which is not divisible by 5.
• For �=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. ## SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.