time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 (gcdgcd) of all its elements should be greater than 11.
Recall that the gcdgcd 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(b1,b2...,bn−1)>1.
Help Ashish find a way to do so.
Input
The first line contains a single integer tt (1≤t≤101≤t≤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≤n≤1000).
The second line of each test case contains 2n2n integers a1,a2,…,a2na1,a2,…,a2n (1≤ai≤10001≤ai≤1000) — the elements of the array aa.
Output
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.
Example
input
Copy
3 3 1 2 3 4 5 6 2 5 7 9 10 5 1 3 3 4 5 90 100 101 2 3
output
Copy
3 6 4 5 3 4 1 9 2 3 4 5 6 10
Note
In the first test case, b={3+6,4+5}={9,9}b={3+6,4+5}={9,9} and gcd(9,9)=9gcd(9,9)=9.
In the second test case, b={9+10}={19}b={9+10}={19} and gcd(19)=19gcd(19)=19.
In the third test case, b={1+2,3+3,4+5,90+3}={3,6,9,93}b={1+2,3+3,4+5,90+3}={3,6,9,93} and gcd(3,6,9,93)=3gcd(3,6,9,93)=3.
解題說明:此題是一道數學題,可以通過構造方法求解。若數組a中有奇數個奇數,此時可以刪掉一個奇數和一個偶數,這樣a中就是剩下了偶數個偶數和偶數個奇數,這樣組合後gcd( b)必定大於2。若a中有偶數個奇數,此時就可以刪掉兩個偶數或者兩個奇數,這樣a中偶數和奇數的個數也還是偶數,組合後gcd( b )必定大於2。
#include<stdio.h>
int main()
{
int t, n, i, j, k;
scanf("%d", &t);
for (i = 1; i <= t; i++)
{
scanf("%d", &n);
int d = 2 * n, a[2002], p = 0;
for (j = 0; j<d; j++)
{
scanf("%d", &a[j]);
}
for (j = 0; j<d; j++)
{
if (a[j] != 0)
{
for (k = j + 1; k<d; k++)
{
if ((a[j] + a[k]) % 2 == 0 && a[k] != 0)
{
printf("%d %d\n", j + 1, k + 1);
a[k] = 0;
p++;
break;
}
}
}
if (p == n - 1)
{
break;
}
}
}
return 0;
}