309637: CF1711A. Perfect Permutation

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Perfect Permutation

题意翻译

一个排列的定义如下: - 该排列的数字必须小于等于排列的长度 $n$ - 该排列的数字必须从包含小于等于 $n$ 的所有元素 一个排列的权值定义:$\sum_{i=1}^{n}[i \mid p_i]$ 给定 $n$,求权值最小的排列。 Translation by @Leonador

题目描述

You are given a positive integer $ n $ . The weight of a permutation $ p_1, p_2, \ldots, p_n $ is the number of indices $ 1\le i\le n $ such that $ i $ divides $ p_i $ . Find a permutation $ p_1,p_2,\dots, p_n $ with the minimum possible weight (among all permutations of length $ n $ ). A permutation is an array consisting of $ n $ distinct integers from $ 1 $ to $ n $ in arbitrary order. For example, $ [2,3,1,5,4] $ is a permutation, but $ [1,2,2] $ is not a permutation ( $ 2 $ appears twice in the array) and $ [1,3,4] $ is also not a permutation ( $ n=3 $ but there is $ 4 $ in the array).

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \leq t \leq 10^4 $ ). The description of the test cases follows. The only line of each test case contains a single integer $ n $ ( $ 1 \leq n \leq 10^5 $ ) — the length of permutation. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式


For each test case, print a line containing $ n $ integers $ p_1, p_2,\dots, p_n $ so that the permutation $ p $ has the minimum possible weight. If there are several possible answers, you can print any of them.

输入输出样例

输入样例 #1

2
1
4

输出样例 #1

1
2 1 4 3

说明

In the first test case, the only valid permutation is $ p=[1] $ . Its weight is $ 1 $ . In the second test case, one possible answer is the permutation $ p=[2,1,4,3] $ . One can check that $ 1 $ divides $ p_1 $ and $ i $ does not divide $ p_i $ for $ i=2,3,4 $ , so the weight of this permutation is $ 1 $ . It is impossible to find a permutation of length $ 4 $ with a strictly smaller weight.

Input

题意翻译

一个排列的定义如下: - 该排列的数字必须小于等于排列的长度 $n$ - 该排列的数字必须从包含小于等于 $n$ 的所有元素 一个排列的权值定义:$\sum_{i=1}^{n}[i \mid p_i]$ 给定 $n$,求权值最小的排列。 Translation by @Leonador

Output

**完美排列**

**题目大意:**
给定一个正整数 $ n $,需要找到一个长度为 $ n $ 的排列 $ p_1, p_2, \ldots, p_n $,使得排列的权值最小。排列的权值定义为满足 $ i $ 能整除 $ p_i $ 的下标 $ i $ 的数量。排列是由 $ n $ 个从 $ 1 $ 到 $ n $ 的不同整数以任意顺序组成的数组。

**输入格式:**
每个测试包含多个测试用例。第一行包含测试用例的数量 $ t $($ 1 \leq t \leq 10^4 $)。接下来是每个测试用例的描述。

每个测试用例只有一行,包含一个整数 $ n $($ 1 \leq n \leq 10^5 $)——排列的长度。

保证所有测试用例的 $ n $ 之和不超过 $ 10^5 $。

**输出格式:**
对于每个测试用例,输出一行包含 $ n $ 个整数 $ p_1, p_2, \ldots, p_n $,以使排列 $ p $ 有最小的权值。

如果有多个可能的答案,可以输出其中任何一个。

**输入输出样例:**
**输入样例 #1:**
```
2
1
4
```
**输出样例 #1:**
```
1
2 1 4 3
```

**说明:**
在第一个测试用例中,唯一的合法排列是 $ p=[1] $。其权值是 $ 1 $。

在第二个测试用例中,一个可能的答案是排列 $ p=[2,1,4,3] $。可以验证 $ 1 $ 能整除 $ p_1 $,且对于 $ i=2,3,4 $,$ i $ 不整除 $ p_i $,所以这个排列的权值是 $ 1 $。不可能找到一个长度为 $ 4 $ 的排列,其权值严格小于 $ 1 $。**完美排列** **题目大意:** 给定一个正整数 $ n $,需要找到一个长度为 $ n $ 的排列 $ p_1, p_2, \ldots, p_n $,使得排列的权值最小。排列的权值定义为满足 $ i $ 能整除 $ p_i $ 的下标 $ i $ 的数量。排列是由 $ n $ 个从 $ 1 $ 到 $ n $ 的不同整数以任意顺序组成的数组。 **输入格式:** 每个测试包含多个测试用例。第一行包含测试用例的数量 $ t $($ 1 \leq t \leq 10^4 $)。接下来是每个测试用例的描述。 每个测试用例只有一行,包含一个整数 $ n $($ 1 \leq n \leq 10^5 $)——排列的长度。 保证所有测试用例的 $ n $ 之和不超过 $ 10^5 $。 **输出格式:** 对于每个测试用例,输出一行包含 $ n $ 个整数 $ p_1, p_2, \ldots, p_n $,以使排列 $ p $ 有最小的权值。 如果有多个可能的答案,可以输出其中任何一个。 **输入输出样例:** **输入样例 #1:** ``` 2 1 4 ``` **输出样例 #1:** ``` 1 2 1 4 3 ``` **说明:** 在第一个测试用例中,唯一的合法排列是 $ p=[1] $。其权值是 $ 1 $。 在第二个测试用例中,一个可能的答案是排列 $ p=[2,1,4,3] $。可以验证 $ 1 $ 能整除 $ p_1 $,且对于 $ i=2,3,4 $,$ i $ 不整除 $ p_i $,所以这个排列的权值是 $ 1 $。不可能找到一个长度为 $ 4 $ 的排列,其权值严格小于 $ 1 $。

加入题单

算法标签: