CF1844B.Permutations & Primes

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a positive integer nn.

In this problem, the MEX⁡\operatorname{MEX} of a collection of integers c1,c2,…,ckc_1,c_2,\dots,c_k is defined as the smallest positive integer xx which does not occur in the collection cc.

The primality of an array a1,…,ana_1,\dots,a_n is defined as the number of pairs (l,r)(l,r) such that 1≤l≤r≤n1 \le l \le r \le n and MEX⁡(al,…,ar)\operatorname{MEX}(a_l,\dots,a_r) is a prime number.

Find any permutation of 1,2,…,n1,2,\dots,n with the maximum possible primality among all permutations of 1,2,…,n1,2,\dots,n.

Note:

  • A prime number is a number greater than or equal to 22 that is not divisible by any positive integer except 11 and itself. For example, 2,5,132,5,13 are prime numbers, but 11 and 66 are not prime numbers.
  • A permutation of 1,2,…,n1,2,\dots,n is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

给你一个正整数 nn。

在本题中,整数集合 c1,c2,…,ckc_1,c_2,\dots,c_k 的 MEX⁡\operatorname{MEX} 定义为未出现在该集合 cc 中的最小正整数 xx。

数组 a1,…,ana_1,\dots,a_n 的**素性(primality)**定义为满足 1≤l≤r≤n1 \le l \le r \le n 且 MEX⁡(al,…,ar)\operatorname{MEX}(a_l,\dots,a_r) 为质数的区间对 (l,r)(l,r) 的个数。

请构造 1,2,…,n1,2,\dots,n 的任意一个排列,使其素性在所有 1,2,…,n1,2,\dots,n 的排列中达到最大可能值。

注意:

  • 质数是指大于等于 22 且除了 11 和它自身外不能被任何正整数整除的数。例如,2,5,132,5,13 是质数,但 11 和 66 不是质数。
  • 1,2,…,n1,2,\dots,n 的一个排列是指由 11 到 nn 这 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数字 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers: a permutation of 1,2,…,n1,2,\dots,n that achieves the maximum possible primality.

If there are multiple solutions, print any of them.

对于每个测试用例,输出 nn 个整数:一个 1,2,…,n1,2,\dots,n 的排列,使得其素性(primality)达到最大可能值。

如果存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    2
    1
    5

    输出#1

    2 1
    1
    5 2 1 4 3

说明/提示

In the first test case, there are 33 pairs (l,r)(l,r) with 1≤l≤r≤21 \le l \le r \le 2, out of which 22 have a prime MEX⁡(al,…,ar)\operatorname{MEX}(a_l,\dots,a_r):

  • (l,r)=(1,1)(l,r) = (1,1): MEX⁡(2)=1\operatorname{MEX}(2) = 1, which is not prime.
  • (l,r)=(1,2)(l,r) = (1,2): MEX⁡(2,1)=3\operatorname{MEX}(2,1) = 3, which is prime.
  • (l,r)=(2,2)(l,r) = (2,2): MEX⁡(1)=2\operatorname{MEX}(1) = 2, which is prime.

Therefore, the primality is 22.

In the second test case, MEX⁡(1)=2\operatorname{MEX}(1) = 2 is prime, so the primality is 11.

In the third test case, the maximum possible primality is 88.

在第一个测试用例中,满足 1≤l≤r≤21 \le l \le r \le 2 的 (l,r)(l,r) 对共有 33 个,其中 22 个子数组的 MEX⁡(al,…,ar)\operatorname{MEX}(a_l,\dots,a_r) 是质数:

  • (l,r)=(1,1)(l,r) = (1,1):MEX⁡(2)=1\operatorname{MEX}(2) = 1,不是质数。
  • (l,r)=(1,2)(l,r) = (1,2):MEX⁡(2,1)=3\operatorname{MEX}(2,1) = 3,是质数。
  • (l,r)=(2,2)(l,r) = (2,2):MEX⁡(1)=2\operatorname{MEX}(1) = 2,是质数。

因此,质性(primality)为 22。

在第二个测试用例中,MEX⁡(1)=2\operatorname{MEX}(1) = 2 是质数,故质性为 11。

在第三个测试用例中,质性的最大可能值为 88。

输入解题思路,AI测评打分。不知道怎么写?

首页