fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. ios_base::sync_with_stdio(false);
  5. cin.tie(NULL);
  6. int t; cin>>t;
  7. while(t--){
  8. int n; cin>>n;
  9. vector<int>a(n);
  10. for(int &x : a) cin>>x;
  11. set<int>di;
  12. for(int i=0;i<n;++i){
  13. for(int j=i+1;j<n;++j){
  14. int d=abs(a[i]-a[j]);
  15. for(int k=1; k*k<=d;++k){
  16. if(d%k==0) {
  17. di.insert(k);
  18. di.insert(d/k);
  19. }
  20. }
  21. }
  22. }
  23. int res=1;
  24. for(int g : di){
  25. unordered_map<int, int>freq;
  26. for(int x : a) freq[x%g]++;
  27. for(auto p : freq) if(p.second>1) res=max(res, g);
  28. }
  29.  
  30. cout<<res<<endl;
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5308KB
stdin
4
2
1 3
5
5 4 3 2 1
3
5 6 7
3
1 11 10
stdout
2
4
2
10