CF1713C.Build Permutation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A 0 -indexed array a of size n is called good if for all valid indices i ( 0≤i≤n−1 ), ai+i is a perfect square † .
Given an integer n . Find a permutation ‡ p of [0,1,2,…,n−1] that is good or determine that no such permutation exists.
† An integer x is said to be a perfect square if there exists an integer y such that x=y2 .
‡ An array b is a permutation of an array a if b consists of the elements of a in arbitrary order. For example, [4,2,3,4] is a permutation of [3,2,4,4] while [1,2,2] is not a permutation of [1,2,3] .
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The only line of each test case contains a single integer n ( 1≤n≤105 ) — the length of the permutation p .
It is guaranteed that the sum of n over all test cases does not exceed 105 .
输出格式
For each test case, output n distinct integers p0,p1,…,pn−1 ( 0≤pi≤n−1 ) — the permutation p — if the answer exists, and −1 otherwise.
输入输出样例
输入#1
3 3 4 7
输出#1
1 0 2 0 3 2 1 1 0 2 6 5 4 3
说明/提示
In the first test case, we have n=3 . The array p=[1,0,2] is good since 1+0=12 , 0+1=12 , and 2+2=22
In the second test case, we have n=4 . The array p=[0,3,2,1] is good since 0+0=02 , 3+1=22 , 2+2=22 , and 1+3=22 .