CF1799B Equalize by Divide
题目描述
给您一个 $a_1,a_2,\dots a_n$ 这样的正整数数组,您可以对它进行多次(可以是零次)这样的操作:
* 选择两个索引 $i,j(1 \leq i,j \leq n,i \neq j)$;
* 将 $a_i$ 赋值为 $\lceil \frac{a_i}{a_j}\rceil$。这里的 $\lceil x \rceil$ 表示将 $x$ 取值到最小的大于等于 $x$ 的整数上。
有可能将通过这样的操作使数组的所有元素相等吗(或许为空)?如果可以,打印任何一种操作次数小于等于 $30n$ 的操作方法。
可以证明,在问题约束下,如果存在让数组所有元素相等的操作方法,那么操作次数最多 $30n$ 次。
输入格式
第一行仅一个正整数 $t(1 \leq t \leq 1000)$,表示测试数据的组数。对于测试数据的描述如下。
每一组测试数据的第一行都仅一个正整数 $n(1 \leq n \leq 100)$。
每一组测试数据的第二行都有 $n$ 个正整数 $a_1,a_2,\dots,a_n(1 \leq a_i \leq 10^9)$。
保证所有测试数据的 $n$ 之和不超过 $1000$。
输出格式
对于每一组测试数据,先输出一个整数 $q(-1 \leq q \leq 30n)$。如果 $q=-1$,表示问题无解,否则 $q$ 表示达成目的所需的操作次数。
若 $q \geq 0$,则接下来的 $q$ 行每行两个正整数 $i,j(1\leq i,j \leq n,i\neq j)$,表示每一次操作中的 $i,j$。
如果问题多解,输出其中任意一个即可。
说明/提示
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: $ [\color{red}{4}, 3, \color{blue}{2}] \to [\color{blue}{2}, \color{red}{3}, 2] \to [2, 2, 2] $ .
In the sixth test case: $ [\color{blue}{3}, 3, \color{red}{4}, 4] \to [3, \color{blue}{3}, 2, \color{red}{4}] \to [\color{red}{3}, 3, \color{blue}{2}, 2] \to [2, \color{red}{3}, 2, \color{blue}{2}] \to [2, 2, 2, 2] $ .
Here the red numbers are $ i $ indices (that will be assigned), blue numbers are $ j $ indices.