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):
N = int(input())

A = list(map(int, input().split()))
A=list(set(A))

print(A)

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

l1=[]


if len(A)==1:
    ans=A[0]

elif len(A)==2:
    ans=max(A)

elif len(A)==3:
    a=gcd(A[0],A[1])
    b=gcd(A[0],A[2])
    c=gcd(A[2],A[1])
    ans=max([a,b,c])

else:
    a=A[0]
    b=A[1]
    if gcd(a,b)==1:
        a=A[2]
        b=A[4]
    
    for x in A:
        l1.append(gcd(gcd(x,a),b))
    np=l1.count(1)
    if np>1:
        ans=1
    else:
        ans=max(l1)

print(ans)

N = int(input())

A = list(map(int, input().split()))
A.sort()

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    for i in range(N):
      if gcd(A[i],c)==1:
        b=A[i]
        break
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(ans)




N = int(input())

A = list(map(int, input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

ans=[]

if N==2:
  sol=max(A[0],A[1])

else:
  for i in range(3):
    B=A[:]
    del B[i]
    sol=0
    for b in B:
        sol=gcd(sol,b)
    ans.append(sol)
    sol=ans


print(sol)



N = int(input())

A = list(map(int, input().split()))
A.argsort()

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    if gcd(c,b)==1:
        b=A[-2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(ans)



N = int(input())

A = list(map(int, input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

ans=[]

for i in range(3):
    B=A[:]
    del B[i]
    sol=0
    for b in B:
        sol=gcd(sol,b)
    ans.append(sol)

print(ans)
print(max(ans))



N = int(input())

A = list(map(int, input().split()))
C=list(set(A))

#print(A)
print(C)
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

anslist=[]

if len(C)==1:
  ans=C[0]

elif len(C)==2:
  sol=max(A[0],A[1])

else:
  for i in range(3):
    B=A[:]
    B.remove(C[i])
    sol=0
    for b in B:
        sol=gcd(sol,b)
    anslist.append(sol)
    ans=max(anslist)

print(anslist)
print(ans)



N = int(input())

A = list(map(int, input().split()))

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

    
elif N==3:
    d=gcd(A[0],A[1])
    b=gcd(A[2],A[1])
    c=gcd(A[2],A[0])
    
    ans=max([d,b,c])
    print(d,b,c)



else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)

print(ans)

N = int(input())

A = list(map(int, input().split()))

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list_koyaku1=[]
list_koyaku11=[]

list_koyaku2=[]
list_koyaku22=[]  

list_koyaku3=[]
list_koyaku33=[]  

if N==2:
    ans=max(A)

    
elif N==3:
    d=gcd(A[0],A[1])
    b=gcd(A[2],A[1])
    c=gcd(A[2],A[0])
    
    ans=max([d,b,c])
    print(d,b,c)

else:
    b=A[0]
    c=A[1]
    d=A[2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
        
    for a in A:
        list_koyaku2.append(gcd(a,c))

    for a in list_koyaku2:
        list_koyaku22.append(gcd(a,d))
        
    for a in A:
        list_koyaku3.append(gcd(a,b))

    for a in list_koyaku2:
        list_koyaku33.append(gcd(a,d))    
        
    ans1=max(list_koyaku11)
    ans2=max(list_koyaku22)
    ans3=max(list_koyaku33)

    ans=max([ans1,ans2,ans3])
        


print(ans)

N = int(input())

A = list(map(int, input().split()))
A.sorted()

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    if gcd(c,b)==1:
        b=A[-2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(ans)



N = int(input())

A = list(map(int, input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N+1):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))





N = int(input())

A = list(map(int, input().split()))

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)



N = int(input())

A = list(map(int, input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))







Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted