Untitled

                Never    
C++
       
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define ll long long
using namespace std;
const int maxn = 1e4 +7;
int b[maxn];

int main(){
 ios;   
 int a , d;
 map <int , int> mp;
 cin >> a ;
 for(int i = 1 ; i <= a ; i++){
    cin >> d;
    for(int j = 1 ; j <= d ; j++){
        cin >> b[j];
         mp[b[j]] = j;
    }
 
 int ans = 0 ;
 for(int k = 1 ; k <= d ; k++ ){
		if((b[k] != mp[b[k]]))
		ans = __gcd(ans , abs(mp[b[k]] - b[k]));
	}
 cout << ans << '\n';
 mp.clear();
 }
	return 0;
} 

Raw Text