Skip to content

Instantly share code, notes, and snippets.

@roy4801
Created September 2, 2019 08:09
Show Gist options
  • Save roy4801/b0ea6847639d7ac100904ef7e2a372a5 to your computer and use it in GitHub Desktop.
Save roy4801/b0ea6847639d7ac100904ef7e2a372a5 to your computer and use it in GitHub Desktop.
/*
* VJUDGE C - GCD on Blackboard
* author: roy4801
* (C++)
*/
#include <bits/stdc++.h>
using namespace std;
#define PROB "C"
#define TESTC ""
#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define MT make_tuple
#define PB push_back
int n, ans;
#define N 1000000
int a[N+5], l[N+5], r[N+5];
int main()
{
#ifdef DBG
freopen("./testdata/" PROB TESTC ".in", "r", stdin);
freopen("./testdata/" PROB ".out", "w", stdout);
#endif
while(cin >> n)
{
for(int i = 0; i < n && cin >> a[i]; i++);
l[0] = a[0];
for(int i = 1; i < n; i++)
l[i] = __gcd(l[i-1], a[i]);
r[n-1] = a[n-1];
for(int i = n-2; i >= 0; i--)
r[i] = __gcd(r[i+1], a[i]);
ans = 1;
for(int i = 1; i < n-1; i++) // [1, n-2]
ans = max(__gcd(l[i-1], r[i+1]), ans);
ans = max(max(l[n-2], r[1]), ans);
printf("%d\n", ans);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment