Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):
import fractions

n = int(input())
As = list(map(int, input().split(" ")))
maxa = max(As)
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
    if largest == max:
      break

print(largest)



import fractions

n = int(input())
As = list(map(int, input().split(" ")))
maxa = max(As)
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
    if largest == maxa:
      break

print(largest)



import fractions

n = int(input())
As = sorted(list(map(int, input().split(" "))))
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
    if largest == As[0] or largest == As[1]:
      break
print(largest)



import fractions

n = int(input())
As = sorted(list(map(int, input().split(" "))))
maxa = As[0]
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    if j - As[idx-1] == 1:
      break
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
print(largest)



import fractions

n = int(input())
As = sorted(list(map(int, input().split(" "))))
maxa = As[0]
largest = 1

for i in range(n):
  gcd = 0
  prev = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
print(largest)



import fractions

n = int(input())
As = list(map(int, input().split(" ")))

largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd

print(largest)



import fractions

n = int(input())
As = sorted(list(map(int, input().split(" "))))
maxa = As[0]
largest = 1

for i in range(n):
  gcd = 0
  prev = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    if prev != 0 and j - prev == 1:
      break
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
    prev = j
  if gcd > largest:
    largest = gcd
print(largest)



def gcd(a, b):
  l = max(a, b)
  s = min(a, b)
  if s == 0:
    return l
  else:
    return gcd(s, l%s)

n = int(input())
A = [0] + list(map(int, input().split())) + [0]
largest = 0
L = [0 for _ in range(n+2)]
R = [0 for _ in range(n+2)]
for i in range(1, n+2):
  L[i] = gcd(A[i], L[i-1])
  R[n-i+1] = gcd(R[n-i+2], A[n-i+1])

print(max(gcd(L[i-1],R[i+1]) for i in range(1, n+1)))


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Accepted