#P17447. 简单构造题 / A Simple Construction Problem

    ID: 19960 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>数学Special Judge构造2026高校校赛

简单构造题 / A Simple Construction Problem

Problem Description

A "Hongzhuan sequence" of length nn is a sequence that satisfies the following properties:

  • Each integer from 11 to nn appears in the sequence exactly once.
  • The sum of every pair of adjacent elements is not a perfect square.

Given an integer nn, construct a "Hongzhuan sequence" of length nn.

Input Format

The first line contains an integer TT (1≤T≤1041\le T\le 10^4), meaning the number of test cases.

For each test case, there is only one line containing one integer nn (1≤n≤4×1061\le n\le 4\times 10^6), meaning the length of the "Hongzhuan sequence" to construct.

It is guaranteed that the sum of all nn does not exceed 4×1064\times 10^6. It can be proven that under the given conditions, a solution always exists.

Output Format

Output TT lines. Each line should be the constructed sequence. If there are multiple solutions, output any one.

5
1
2
3
4
5
1
1 2
1 2 3
1 2 3 4
1 4 2 3 5

Hint

For n=5n = 5, if the output is 1 2 3 4 5, it is wrong, because 4+5=94 + 5 = 9 is a perfect square.

Translated by ChatGPT 5