-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllAreTheSame.cc
45 lines (42 loc) · 999 Bytes
/
AllAreTheSame.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef LOCAL
#pragma GCC optimize(2)
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define pb push_back
#define fst first
#define snd second
#define ALL(cont) cont.begin(), cont.end()
#define mset(a,b) memset(a,b,sizeof(a));
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int main()
{
FIN;
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
#define endl '\n'
#endif
int t;cin>>t;
while(t--){
int n;cin>>n;
vi a(n);
fore(i,0,n)cin>>a[i];
int m = *min_element(ALL(a));
vi a2;
fore(i,0,n)if(a[i]!=m)a2.pb(a[i]-m);
ll ans = 0;
if(SZ(a2)){
ans=a2[0];
fore(i,0,SZ(a2))ans = __gcd(ans,a2[i]);
}
cout<<(ans?ans:-1)<<endl;
}
return 0;
}