CF1370B.GCD Compression

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ashish has an array aa of consisting of 2n2n positive integers. He wants to compress aa into an array bb of size n−1n-1. To do this, he first discards exactly 22 (any two) elements from aa. He then performs the following operation until there are no elements left in aa:

  • Remove any two elements from aa and append their sum to bb.

The compressed array bb has to have a special property. The greatest common divisor (gcd\mathrm{gcd}) of all its elements should be greater than 11.

Recall that the gcd\mathrm{gcd} of an array of positive integers is the biggest integer that is a divisor of all integers in the array.

It can be proven that it is always possible to compress array aa into an array bb of size n−1n-1 such that gcd(b1,b2...,bn−1)>1gcd(b_1, b_2..., b_{n-1}) \gt 1.

Help Ashish find a way to do so.

阿希什有一个由 2n2n 个正整数组成的数组 aa。他希望将 aa 压缩为一个大小为 n−1n-1 的数组 bb。为此,他首先恰好从 aa 中丢弃 22 个(任意两个)元素。然后重复执行以下操作,直至 aa 中没有剩余元素:

  • 从 aa 中任取两个元素,将其和添加到 bb 的末尾。

压缩得到的数组 bb 必须满足一个特殊性质:其所有元素的最大公约数(gcd\mathrm{gcd})必须大于 11。

回忆一下,一个正整数数组的 gcd\mathrm{gcd} 是能整除该数组中所有整数的最大整数。

可以证明:总存在一种方式,将数组 aa 压缩为大小为 n−1n-1 的数组 bb,使得 gcd⁡(b1,b2,…,bn−1)>1\gcd(b_1, b_2, \dots, b_{n-1}) > 1。

请帮助阿希什找到这样一种压缩方法。

输入格式

The first line contains a single integer tt (1≤t≤101 \leq t \leq 10) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤10002 \leq n \leq 1000).

The second line of each test case contains 2n2n integers a1,a2,…,a2na_1, a_2, \ldots, a_{2n} (1≤ai≤10001 \leq a_i \leq 1000) — the elements of the array aa.

第一行包含一个整数 tt(1≤t≤101 \leq t \leq 10)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤10002 \leq n \leq 1000)。

每个测试用例的第二行包含 2n2n 个整数 a1,a2,…,a2na_1, a_2, \ldots, a_{2n}(1≤ai≤10001 \leq a_i \leq 1000)—— 表示数组 aa 的元素。

输出格式

For each test case, output n−1n-1 lines — the operations performed to compress the array aa to the array bb. The initial discard of the two elements is not an operation, you don't need to output anything about it.

The ii-th line should contain two integers, the indices (11 —based) of the two elements from the array aa that are used in the ii-th operation. All 2n−22n-2 indices should be distinct integers from 11 to 2n2n.

You don't need to output two initially discarded elements from aa.

If there are multiple answers, you can find any.

对每个测试用例,输出 n−1n-1 行——即用于将数组 aa 压缩为数组 bb 的操作。初始丢弃的两个元素不视为一次操作,你无需对此输出任何内容。

第 ii 行应包含两个整数,表示在第 ii 次操作中所使用的数组 aa 中两个元素的下标(从 1 开始计数)。所有 2n−22n-2 个下标必须是 11 到 2n2n 范围内互不相同的整数。

你无需输出数组 aa 中最初被丢弃的两个元素的下标。

若存在多种答案,输出任意一种即可。

输入输出样例

  • 输入#1

    3
    3
    1 2 3 4 5 6
    2
    5 7 9 10
    5
    1 3 3 4 5 90 100 101 2 3

    输出#1

    3 6
    4 5
    3 4
    1 9
    2 3
    4 5
    6 10

说明/提示

In the first test case, b=3+6,4+5=9,9b = {3+6, 4+5} = {9, 9} and gcd(9,9)=9\mathrm{gcd}(9, 9) = 9.

In the second test case, b=9+10=19b = {9+10} = {19} and gcd(19)=19\mathrm{gcd}(19) = 19.

In the third test case, b=1+2,3+3,4+5,90+3=3,6,9,93b = {1+2, 3+3, 4+5, 90+3} = {3, 6, 9, 93} and gcd(3,6,9,93)=3\mathrm{gcd}(3, 6, 9, 93) = 3.

在第一个测试用例中,b=3+6,4+5=9,9b = {3+6, 4+5} = {9, 9},且 gcd(9,9)=9\mathrm{gcd}(9, 9) = 9。

在第二个测试用例中,b=9+10=19b = {9+10} = {19},且 gcd(19)=19\mathrm{gcd}(19) = 19。

在第三个测试用例中,b=1+2,3+3,4+5,90+3=3,6,9,93b = {1+2, 3+3, 4+5, 90+3} = {3, 6, 9, 93},且 gcd(3,6,9,93)=3\mathrm{gcd}(3, 6, 9, 93) = 3。

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

首页