#K57347. Equalize Array Operation

    ID: 30400 Type: Default 1000ms 256MiB

Equalize Array Operation

Equalize Array Operation

You are given T test cases. In each test case, you are provided with an integer N and an array A of N positive integers. Your task is to determine if it is possible to perform an operation to make all elements of the array equal.

The operation is defined as follows: compute the greatest common divisor (gcd) of all elements in the array. If \( \gcd(A_1, A_2, \ldots, A_N) \) is greater than 1, then you can equalize the array in one operation (print 1). Otherwise, if the \( \gcd \) is equal to 1, the operation is impossible (print -1).

Note: You should read input from stdin and write your output to stdout.

inputFormat

The first line contains a single integer T, the number of test cases.

For each test case, the first line contains an integer N, the number of elements in the array. The next line contains N space-separated integers representing the array elements.

Example:

3
3
2 4 6
4
1 5 2 7
3
3 3 3

outputFormat

For each test case, output a single integer on a new line. Print 1 if it is possible to equalize the array using one operation, otherwise print -1.

Example:

1
-1
1
## sample
3
3
2 4 6
4
1 5 2 7
3
3 3 3
1

-1 1

</p>