题目
思路:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 5;
int a[maxn], b[maxn], c[maxn];
void solve(){
int n, k;
cin >> n >> k;
int g = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] -= k;
g = __gcd(g, abs(a[i]));
}
sort(a + 1, a + n + 1);
if(g == 0){
cout << "0\n";
return;
}
if(a[1] <= 0 && a[n] >= 0){
cout << "-1\n";
return;
}
int res = 0;
for(int i = 1; i <= n; i++){
// cout << a[i] << ' ';
res += abs(a[i]) / g;
}
cout << res - n << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while(T--){
solve();
}
}