CF1713C.Build Permutation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A 0\mathbf{0} -indexed array aa of size nn is called good if for all valid indices ii ( 0in10 \le i \le n-1 ), ai+ia_i + i is a perfect square ^\dagger .

Given an integer nn . Find a permutation ^\ddagger pp of [0,1,2,,n1][0,1,2,\ldots,n-1] that is good or determine that no such permutation exists.

^\dagger An integer xx is said to be a perfect square if there exists an integer yy such that x=y2x = y^2 .

^\ddagger An array bb is a permutation of an array aa if bb consists of the elements of aa in arbitrary order. For example, [4,2,3,4][4,2,3,4] is a permutation of [3,2,4,4][3,2,4,4] while [1,2,2][1,2,2] is not a permutation of [1,2,3][1,2,3] .

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The only line of each test case contains a single integer nn ( 1n1051 \le n \le 10^5 ) — the length of the permutation pp .

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 .

输出格式

For each test case, output nn distinct integers p0,p1,,pn1p_0, p_1, \dots, p_{n-1} ( 0pin10 \le p_i \le n-1 ) — the permutation pp — if the answer exists, and 1-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=3n=3 . The array p=[1,0,2]p = [1, 0, 2] is good since 1+0=121 + 0 = 1^2 , 0+1=120 + 1 = 1^2 , and 2+2=222 + 2 = 2^2

In the second test case, we have n=4n=4 . The array p=[0,3,2,1]p = [0, 3, 2, 1] is good since 0+0=020 + 0 = 0^2 , 3+1=223 + 1 = 2^2 , 2+2=222+2 = 2^2 , and 1+3=221+3 = 2^2 .

首页