Maruf_Hasan

The chosen one

Nov 27th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef unsigned long long ll;
  6. const ll MAX=1e5+5;
  7. ll age[MAX];
  8. ll pore[MAX];
  9. int main()
  10. {
  11. int n;
  12. cin >> n;
  13. ll a[n];
  14. ll m=0;
  15. for(int i=0;i<n;i++)
  16. {
  17. cin>>a[i];
  18. m=max(m,a[i]);
  19. }
  20. for(int i=1;i<n;i++)
  21. {
  22. age[i]=__gcd(age[i-1],a[i-1]);
  23. }
  24. for(int i=n-2;i>=0;i--)
  25. {
  26. pore[i]=__gcd(pore[i+1],a[i+1]);
  27. }
  28. for(int i=0;i<n;i++)
  29. {
  30. ll ans=__gcd(age[i],pore[i]);
  31. if( ans!= 0 && a[i]%ans!=0)
  32. {
  33. cout<<ans<<endl;
  34. return 0;
  35. }
  36. }
  37. cout<<m+1<<endl;
  38. }
Add Comment
Please, Sign In to add comment