题目描述
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
You are given $N non-negative integers A_{1}, A_{2}, \ldots, A_{N}.$ You are allowed to perform following operation any number of times:
Choose any valid index i (1 ≤ i ≤ N) and a positive integer M>0 and replace A_{i} with $A_{i}\bmod M$. That is, replace A_{i} with its remainder when divided by M, which is a value between 0 and M-1, inclusive.
M does not need to be same between different operations.
Find the minimum number of operations to make all the array elements equal.
Note: Since the input and output are large, prefer using fast input-output methods.
------ Input Format ------
- The first line contains an integer T - the number of test cases. Then T test cases follow.
- The first line of each test case contains an integer N - the size of array.
- The second line contains $N integers A_{1}, A_{2}, \ldots, A_{N} -$ the elements of the array.
------ Output Format ------
For each test, print one line containing an integer which denotes minimum number of operations performed to make all the elements equal.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ A_{i} ≤ 2 \cdot 10^{9}$
- It is guaranteed that the sum of $N$ over all test cases does not exceed $10^{6}$.
----- Sample Input 1 ------
2
3
2 1 3
3
1 1 3
----- Sample Output 1 ------
3
1
----- explanation 1 ------
In first test case, we can make all the elements equal by following operations:
* Take $i = 1$ and $M = 2$ and do $A_{1} := A_{1} \bmod 2 = 0$.
* Take $i = 2$ and $M = 1$ and do $A_{2} := A_{2} \bmod 1 = 0$.
* Take $i = 3$ and $M = 3$ and do $A_{3} := A_{3} \bmod 3 = 0$.
After these $3$ operations we have all the elements equal to zero.
In second test case, we can perform following operation:
* Choose $i = 3$ and $M = 2$ and do $A_{3} := A_{3} \bmod 2 = 1$.
After this operation all the elements are $1$.
输入格式
见题面
输出格式
见题面