Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define all(x) x.begin(), x.end()
- #define revall(x) x.rbegin(), x.rend()
- #define OJ \
- freopen("input.txt", "r", stdin); \
- freopen("output.txt", "w", stdout);
- using namespace std;
- int mod = 1000000007;
- int gcd(ll a, ll b)
- {
- if (a == 0)
- return b;
- return gcd(b % a, a);
- }
- void solve()
- {
- int n;
- cin>>n;
- int a[n];
- for(int i=0;i<n;i++){
- cin>>a[i];
- }
- sort(a,a+n);
- set<int> pos;
- for(int i=1;i*i<=a[0];i++){
- if(a[0]%i==0){
- pos.insert(i);
- pos.insert(a[0]/i);
- }
- }
- for(int i=1;i*i<=a[0]+1;i++){
- if((a[0]+1)%i==0){
- pos.insert(i);
- pos.insert((a[0]+1)/i);
- }
- }
- for(int i=1;i*i<=(a[0]-1);i++){
- if((a[0]-1)%i==0){
- pos.insert(i);
- pos.insert((a[0]-1)/i);
- }
- }
- int ans=0;
- for(auto j:pos){
- int cur=j;
- // cout<<j<<" ";
- for(int i=0;i<n;i++){
- if(a[i]%j!=0&&(a[i]-1)%j!=0&&(a[i]+1)%j!=0){
- //cout<<a[i]<<" ";
- cur=0;
- break;
- }
- }
- ans=max(ans,cur);
- }
- cout<<ans<<endl;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- // OJ;
- int T = 1;
- cin >> T;
- while (T--)
- {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement