Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Pratica 01-Instic training  

  Nov 08, 2022

Problem Q. Avoid Squares Please


Time limit 1000 ms
Code length Limit 50000 B
OS Linux

You are given an integer N .

Print a permutation P of [1, 2, … , N] such that the following condition holds:

For any index i (1 ≤ i < N), Pi × Pi+1 is not a perfect square.
​ ​

If there are multiple correct answers, you may print any of them.

Note: A permutation of [1, 2, … , N] is a rearrangement of those numbers.

Input Format

The first line of input contains a single integer T , denoting the number of test cases. The
description of T test cases follows.
The first line of each test case contains an integer N - the length of the required
permutation.

Output Format

For each test case, print N space-separated integers representing the valid permutation on a
single line.

If there are multiple correct answers, you may print any of them.

Constraints

1 ≤ T ≤ 500
2 ≤ N ≤ 500

Sample 1
Input Output

3
2 1

2
3 1 2
3
4 2 3 1

Test case 1: 2 × 1 = 2 is not a perfect square. Note that [1, 2] is also a valid answer for this case,
and will be accepted.

-
Pratica 01-Instic training    Nov 08, 2022
Test case 2: 3 × 1 = 3 and 1 × 2 = 2 are not perfect squares.

Test case 3: 4 × 2 = 8, 2 × 3 = 6, 3 × 1 = 3 are all not perfect squares.

You might also like