#K46482. Minimum Operations to Make Array Equal
Minimum Operations to Make Array Equal
Minimum Operations to Make Array Equal
You are given an array of positive integers. In one operation, you can choose any element of the array and replace it with the result of integer division by 2 (i.e. floor division by 2). The goal is to make all elements of the array equal using the minimum total number of operations.
More formally, for an array \(A = [a_1, a_2, \dots, a_N]\), you can perform the following operation on any element \(a_i\):
[ a_i \leftarrow \left\lfloor \frac{a_i}{2} \right\rfloor ]
Your task is to calculate the minimum total operations required such that after applying the operations, all the array elements become equal.
Note: It is guaranteed that it is always possible to make the elements equal.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N_1 a1 a2 ... aN1 N_2 a1 a2 ... aN2 ... N_T a1 a2 ... aN_T
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N, the size of the array.
- The following line contains N space-separated positive integers.
outputFormat
For each test case, print a single integer on a new line representing the minimum total number of operations required to make all the array elements equal.
## sample3
3
4 8 16
4
3 6 12 24
2
5 10
3
6
1
</p>