CF1844B.Permutations & Primes

普及/提高-

通过率:0%

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 1lrn1 \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).

输入格式

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

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

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \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.

输入输出样例

  • 输入#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 1lr21 \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 .

首页