CF1799B.Equalize by Divide
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an of positive integers.
You can make this operation multiple (possibly zero) times:
- Choose two indices i , j ( 1≤i,j≤n , i=j ).
- Assign ai:=⌈ajai⌉ . Here ⌈x⌉ denotes x rounded up to the smallest integer ≥x .
Is it possible to make all array elements equal by some sequence of operations (possibly empty)? If yes, print any way to do it in at most 30n operations.
It can be proven, that under the problem constraints, if some way exists to make all elements equal, there exists a way with at most 30n operations.
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases. Descriptions of test cases follow.
The first line of each test case description contains a single integer n ( 1≤n≤100 ).
The second line of each test case description contains n integers a1,a2,…,an ( 1≤ai≤109 ).
It is guaranteed, that the sum of n for all test cases does not exceed 1000 .
输出格式
For each test case print a single integer q ( −1≤q≤30n ). If q=−1 , there is no solution, otherwise q is equal to the number of operations.
If q≥0 , on the next q lines print two integers i , j ( 1≤i,j≤n , i=j ) — descriptions of operations.
If there are multiple solutions, you can print any.
输入输出样例
输入#1
10 1 100 3 1 1 1 2 2 1 2 5 5 3 4 3 2 4 3 3 4 4 2 2 100 5 5 3 6 7 8 6 3 3 80 3 8 3 4 19 40 19 55
输出#1
0 0 -1 0 2 1 3 2 1 4 3 1 4 2 1 3 2 4 6 2 1 2 1 2 1 2 1 2 1 2 1 8 5 2 4 2 3 2 1 3 1 3 2 1 4 1 5 1 4 5 1 3 1 3 1 3 1 9 4 2 2 1 1 2 1 2 3 2 3 2 1 4 2 4 3 4
说明/提示
In the first and second, fourth test cases all numbers are equal, so it is possible to do nothing.
In the third test case, it is impossible to make all numbers equal.
In the fifth test case: [4,3,2]→[2,3,2]→[2,2,2] .
In the sixth test case: [3,3,4,4]→[3,3,2,4]→[3,3,2,2]→[2,3,2,2]→[2,2,2,2] .
Here the red numbers are i indices (that will be assigned), blue numbers are j indices.