• + 0 comments
    #include <bits/stdc++.h>
    #define ll long long 
    using namespace std;
    
    ll __gcd(ll a, ll b){
        if(b == 0)
            return a;
        return __gcd(b,a%b);
    }
    
    signed main()
    {
        ll n ;
        cin >> n;
        
        ll a[100000+1];
        
        for(ll i=0;i<n;++i)
            cin >> a[i];
            
        sort(a,a+n);
            
        if(n==1){
            cout << a[0] + 1 << endl;
            return 0;
        }
        
        assert(n >= 2);
        ll prefix[100000+1]{0} , suffix[100000+1]{0};
        
        ll gcd = 0;
        for(ll i=0;i<n;++i){
            gcd = __gcd(gcd,a[i]);
            prefix[i] = gcd;
        }
        
        gcd = 0;
        for(ll i=n-1;i>=0;--i){
            gcd = __gcd(gcd,a[i]);
            suffix[i] = gcd;
        }
        
        if(a[0]%suffix[1]){
            cout << suffix[1] << endl;
        }
        else if(a[n-1]%prefix[n-2])
        {
            cout << prefix[n-2] << endl;
        }
        else{
        for(ll i=1;i<n-1;++i){
            ll preGcd = __gcd(suffix[i+1],prefix[i-1]);
            if(a[i]%preGcd)
                {
                    cout << preGcd << endl;
                    break;
                }
        }
        }   
        return 0;
    }