#P16462. [UOI 2026] Divisors
[UOI 2026] Divisors
题目描述
You are given integers and an integer . For all , it holds that .
In one operation, you may choose any index () and increase the number by .
You need to perform no more than operations and split all numbers into pairs so that in each pair, after performing the operations, one number is divisible by the other.
In other words, you need to find non-negative integers and a partition of the indices into pairs such that:
- $\sum\limits_{i=1}^{2n} d_i \le \left\lfloor \frac{x}{2} \right\rfloor$, that is, the sum of all does not exceed rounded down;
- if , then for every pair of indices , either or , that is, either divides or divides .
It is guaranteed that for the given constraints, an answer always exists.
denotes the greatest integer not exceeding . For example, .
输入格式
The first line contains one integer --- the number of test cases.
Each test case consists of two lines.
The first line of a test case contains two integers and (, ).
The second line contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output the answer in the following format.
First, output lines. In the -th of them, output two integers and --- the indices of the numbers that form the -th pair.
Each index from to must appear in exactly one pair.
After that, output one line with integers , where is the number of operations performed on the number .
The following must hold: for all , and also $\sum\limits_{i=1}^{2n} d_i \le \left\lfloor \frac{x}{2} \right\rfloor.$
Let . For each printed pair , it must hold that: $c_{u_j} \mid c_{v_j} \quad \text{or} \quad c_{v_j} \mid c_{u_j}.$
If there are multiple correct answers, you may output any of them.
2
4 8
3 1 4 2 5 3 8 5
3 8
7 2 6 3 5 8
1 6
2 7
3 4
5 8
0 0 0 0 0 0 0 0
2 3
4 6
1 5
3 0 0 0 0 1
提示
In the first example, we can split the numbers into pairs , , , and . In each pair, one number is divisible by the other, so we do not perform any operations.
In the second example, we add to the first number and to the last one. We obtain the new array: . After that, we split the numbers into pairs , , and . The total number of operations is $3+1 = 4 \leq \left\lfloor \frac{x}{2} \right\rfloor = 4$. Note that this is not the minimum possible number of operations.
Scoring
- ( points): , , .
- ( points): , , .
- ( points): , .
- ( points): for all .
- ( points): for each , either or .
- ( points): the answer can be obtained without performing any operations. All numbers are powers of prime numbers, all numbers do not exceed , .
- ( points): the answer can be obtained without performing any operations. Each number is a product of at most two prime numbers, each prime number appears in the factorization of all numbers in total at most twice, all numbers do not exceed , .
- ( points): There exists an answer where the adjacent numbers of the initial array can be paired: . Also, and .
- ( points): no additional constraints.