Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ll;
- const ll MAX=1e5+5;
- ll age[MAX];
- ll pore[MAX];
- int main()
- {
- int n;
- cin >> n;
- ll a[n];
- ll m=0;
- for(int i=0;i<n;i++)
- {
- cin>>a[i];
- m=max(m,a[i]);
- }
- for(int i=1;i<n;i++)
- {
- age[i]=__gcd(age[i-1],a[i-1]);
- }
- for(int i=n-2;i>=0;i--)
- {
- pore[i]=__gcd(pore[i+1],a[i+1]);
- }
- for(int i=0;i<n;i++)
- {
- ll ans=__gcd(age[i],pore[i]);
- if( ans!= 0 && a[i]%ans!=0)
- {
- cout<<ans<<endl;
- return 0;
- }
- }
- cout<<m+1<<endl;
- }
Add Comment
Please, Sign In to add comment