CF1844B.Permutations & Primes
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer n.
In this problem, the MEX of a collection of integers c1,c2,…,ck is defined as the smallest positive integer x which does not occur in the collection c.
The primality of an array a1,…,an is defined as the number of pairs (l,r) such that 1≤l≤r≤n and MEX(al,…,ar) is a prime number.
Find any permutation of 1,2,…,n with the maximum possible primality among all permutations of 1,2,…,n.
Note:
- A prime number is a number greater than or equal to 2 that is not divisible by any positive integer except 1 and itself. For example, 2,5,13 are prime numbers, but 1 and 6 are not prime numbers.
- A permutation of 1,2,…,n 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).
给你一个正整数 n。
在本题中,整数集合 c1,c2,…,ck 的 MEX 定义为未出现在该集合 c 中的最小正整数 x。
数组 a1,…,an 的**素性(primality)**定义为满足 1≤l≤r≤n 且 MEX(al,…,ar) 为质数的区间对 (l,r) 的个数。
请构造 1,2,…,n 的任意一个排列,使其素性在所有 1,2,…,n 的排列中达到最大可能值。
注意:
- 质数是指大于等于 2 且除了 1 和它自身外不能被任何正整数整除的数。例如,2,5,13 是质数,但 1 和 6 不是质数。
- 1,2,…,n 的一个排列是指由 1 到 n 这 n 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,但 [1,2,2] 不是排列(数字 2 出现了两次),[1,3,4] 也不是排列(此时 n=3,但数组中出现了 4)。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains a single integer n (1≤n≤2⋅105).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(1≤n≤2⋅105)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output n integers: a permutation of 1,2,…,n that achieves the maximum possible primality.
If there are multiple solutions, print any of them.
对于每个测试用例,输出 n 个整数:一个 1,2,…,n 的排列,使得其素性(primality)达到最大可能值。
如果存在多个解,输出任意一个即可。
输入输出样例
输入#1
3 2 1 5
输出#1
2 1 1 5 2 1 4 3
说明/提示
In the first test case, there are 3 pairs (l,r) with 1≤l≤r≤2, out of which 2 have a prime MEX(al,…,ar):
- (l,r)=(1,1): MEX(2)=1, which is not prime.
- (l,r)=(1,2): MEX(2,1)=3, which is prime.
- (l,r)=(2,2): MEX(1)=2, which is prime.
Therefore, the primality is 2.
In the second test case, MEX(1)=2 is prime, so the primality is 1.
In the third test case, the maximum possible primality is 8.
在第一个测试用例中,满足 1≤l≤r≤2 的 (l,r) 对共有 3 个,其中 2 个子数组的 MEX(al,…,ar) 是质数:
- (l,r)=(1,1):MEX(2)=1,不是质数。
- (l,r)=(1,2):MEX(2,1)=3,是质数。
- (l,r)=(2,2):MEX(1)=2,是质数。
因此,质性(primality)为 2。
在第二个测试用例中,MEX(1)=2 是质数,故质性为 1。
在第三个测试用例中,质性的最大可能值为 8。
输入解题思路,AI测评打分。不知道怎么写?