fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. typedef long long ll;
  4. using namespace std;
  5.  
  6. void solve() {
  7. int n;
  8. cin>>n;
  9. vector<int> v(n);
  10. for(int i=0;i<n;i++)cin>>v[i];
  11. int x=0;
  12. int i=0,j=n-1;
  13. while(i<j){
  14. int z=abs(v[i]-v[j]);
  15. x=__gcd(x,z);
  16. i++;
  17. j--;
  18. }
  19. cout<<x<<endl;
  20.  
  21. }
  22.  
  23. signed main() {
  24. int t;
  25. cin >> t;
  26. while (t--) {
  27. solve();
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5280KB
stdin
1
4
3 4 3 1
stdout
1