Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- int inf_int=2e9;
- ll inf_ll=2e18;
- typedef pair<int,int> pii;
- #define pb push_back
- const double pi=3.1415926535898;
- #define dout if(debug) cout
- #define fi first
- #define se second
- #define sp setprecision
- #define sz size()
- #define x1 gfgs
- #define y1 asd
- #define rank asdsad
- bool debug=0;
- const int maxn=5e5+107;
- ll mod=1e9+7;
- void solve()
- {
- int n;
- cin >> n;
- int a[n];
- for(int i=0;i<n;i++)
- {
- cin >> a[i];
- }
- if(n==2)
- {
- cout << min(a[0],a[1])<<"\n";
- return;
- }
- int ans=1;
- int x=a[0];
- for(int i=1;i*i<=x;i++)
- {
- if(x%i==0)
- {
- int nod2=-1;
- for(int e=1;e<n;e++)
- {
- if(a[e]%i==0)
- {
- continue;
- }
- else
- {
- if(nod2==-1)
- {
- nod2=a[e];
- }
- else
- {
- nod2=__gcd(nod2,a[e]);
- }
- if(nod2<ans)
- break;
- }
- }
- if(nod2==-1)
- {
- nod2=i;
- }
- ans=max(ans,min(nod2,i));
- int del=x/i;
- nod2=-1;
- for(int e=1;e<n;e++)
- {
- if(a[e]%del==0)
- {
- continue;
- }
- else
- {
- if(nod2==-1)
- {
- nod2=a[e];
- }
- else
- {
- nod2=__gcd(nod2,a[e]);
- }
- if(nod2<ans)
- break;
- }
- }
- if(nod2==-1)
- {
- nod2=del;
- }
- ans=max(ans,min(nod2,del));
- }
- }
- cout << ans<<"\n";
- }
- #define FILE "bridges"
- int main()
- {
- // freopen("a.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // freopen(FILE".in","r",stdin);
- // freopen(FILE".out","w",stdout);
- if(!debug)
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- }
- int t=1;
- cin >> t;
- while(t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement