#K67197. Equalizing Array Elements
Equalizing Array Elements
Equalizing Array Elements
In this problem, you are given several arrays of integers. You can perform the following operation any number of times: pick any two integers (a) and (b) from the array and replace both with their arithmetic mean (\frac{a+b}{2}), with the restriction that the result of the operation must be an integer. Your task is to determine whether it is possible to make all elements of the array equal by applying such operations.
Note that for any array with a single element, the answer is trivially "YES". For arrays of length greater than one, an approach based on computing the greatest common divisor ((\gcd)) of the elements can be used to decide the feasibility of equalization.
Formally, given an array (A = [a_1, a_2, \dots, a_n]), in one operation you choose any indices (i \neq j) and update both (a_i) and (a_j) to (\frac{a_i + a_j}{2}) (which is required to be an integer). Determine if, after a finite number of such operations, it is possible to have (a_1 = a_2 = \cdots = a_n).
inputFormat
Input is read from standard input (stdin). The first line contains a single integer (t) (the number of test cases).
For each test case, the first integer is (n) (the number of elements in the array), followed by (n) space-separated integers representing the array elements.
For example:
4
4 3 3 6 12
2 8 9
3 1 2 3
1 1000000000
outputFormat
For each test case, output a single line containing either "YES" if it is possible to make all elements of the array equal using the allowed operations, or "NO" otherwise. Output is written to standard output (stdout).## sample
4
4 3 3 6 12
2 8 9
3 1 2 3
1 1000000000
YES
YES
YES
YES
</p>