-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC125_C.py
More file actions
31 lines (25 loc) · 804 Bytes
/
ABC125_C.py
File metadata and controls
31 lines (25 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
rev_a = list(reversed(a))
ans = 0
accumulation_gcd = [0] * n
rev_accumulation_gcd = [0] * n
accumulation_gcd[0] = a[0]
rev_accumulation_gcd[0] = rev_a[0]
for i in range(1, n):
accumulation_gcd[i] = f.gcd(a[i], accumulation_gcd[i-1])
rev_accumulation_gcd[i] = f.gcd(rev_a[i], rev_accumulation_gcd[i-1])
rev_accumulation_gcd.reverse()
for i in range(n):
if i == 0:
ans = max(ans, rev_accumulation_gcd[1])
elif i == (n - 1):
ans = max(ans, accumulation_gcd[n-2])
else:
ans = max(ans, f.gcd(accumulation_gcd[i-1], rev_accumulation_gcd[i+1]))
print(ans)