#K33672. GCD Equalization Operations

    ID: 25140 Type: Default 1000ms 256MiB

GCD Equalization Operations

GCD Equalization Operations

You are given an array of positive integers. In one operation, you can replace any element with another integer provided that the greatest common divisor (GCD) of the entire array remains the same.

Your task is to determine the minimum number of operations required to make all elements in the array equal.

For an array \(A = [a_1, a_2, \dots, a_n]\), let \(g = \gcd(a_1, a_2, \dots, a_n)\). It is optimal to change every element that is not equal to \(g\) into \(g\) (each such change counts as one operation).

The answer for each test case is the number of elements in the array that are not equal to \(g\).

inputFormat

The first line contains an integer \(T\) indicating the number of test cases.

Each test case starts with an integer \(n\) denoting the number of elements in the array, followed by a line with \(n\) space-separated integers representing the array.

Example:

3
3
2 4 6
4
10 20 30 40
5
5 5 5 5 5

outputFormat

For each test case, output a single integer on a new line — the minimum number of operations required to make the array elements equal while keeping the overall GCD unchanged.

Example:

2
3
0
## sample
3
3
2 4 6
4
10 20 30 40
5
5 5 5 5 5
2

3 0

</p>