#K12086. Operations to Equalize Array via GCD Replacement

    ID: 23612 Type: Default 1000ms 256MiB

Operations to Equalize Array via GCD Replacement

Operations to Equalize Array via GCD Replacement

You are given an array of positive integers. In one operation, you can replace any element of the array with the greatest common divisor (GCD) of the current array elements. The goal is to determine the minimum number of operations needed so that all elements become equal.

Observation: If all the elements are already equal, no operations are needed. Otherwise, the answer is equal to n − 1, where n is the number of array elements.

This problem requires you to process multiple test cases. For each test case, you will first be given n, the number of elements in the array, followed by n space-separated integers. For each test case, print the minimum number of operations required on a new line.

inputFormat

The first line of input contains an integer T denoting the number of test cases.
For each test case, the first line contains an integer n (the size of the array). The second line contains n space-separated positive integers representing the array elements.

outputFormat

For each test case, output a single integer on a new line which is the minimum number of operations required to make all the elements equal.

## sample
3
2
4 8
3
2 3 6
4
7 7 7 7
1

2 0

</p>