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):
def gcd(a,b):
    if a <= b:
        a,b = b,a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = []
for i in range(N-2):
    ans.append(gcd(L_gcd[i],R_gcd[i+2]))
print(max(ans))

N = int(input())
A = list(map(int, input().split()))
def gcd(X):
    X.sorted
    m = min(X)
    for i in len(X):
        X[i] = X[i]%m
    if X == [0] * len(X):
        return m
    else:
        while 0 in X:
            X.remove(0)
        return gcd(X)

ans = 1
tmp = A
for i in range(N):
    A.pop(i)
    if gcd(A) > ans:
        gcd(A) = ans
    A = tmp
print(ans)

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

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i],R_gcd[A[N-i+1]]))

ans = max(L_gcd[-1],R_gcd[0])

for i in range(N-1):
    if gcd(L_gcd[i],R_gcd[i+2]):
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

ef gcd(a,b):
    if a <= b:
        a,b = b,a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = max(L_gcd[-1],R_gcd[0])

for i in range(N-2):
    if max(L_gcd[i],R_gcd[i+2])<=ans:
        break
    if gcd(L_gcd[i],R_gcd[i+2])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

def gcd(a,b):
    if a <= b:
        a,b = b,a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = [max(L_gcd[-1],R_gcd[0])]
for i in range(N-2):
    ans.append(gcd(L_gcd[i],R_gcd[i+2]))
print(max(ans))

N = int(input())
A = list(map(int, input().split()))
def gcd(X):
    X.sorted
    m = min(X)
    for i in len(X):
        X[i] = X[i]%m
    if X == [0] * len(X):
        return m
    else:
        while 0 in X:
            X.remove(0)
        return gcd(X)

ans = 1
tmp = A
for i in range(N):
    A.pop(i)
    if gcd(A) > ans:
        ans = gcd(A)
    A = tmp
print(ans)
    

def gcd(a,b):
    if a <= b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [0]*(N)
R_gcd = [0]*(N)

for i in range(N):
    L_gcd[i] = gcd(L_gcd[i-1],A[i])
for i in reversed(range(N)):   
    R_gcd[i] = gcd(R_gcd[i-1],A[i])

ans = max(L_gcd[-1],R_gcd[0])
for i in range(N):
    if gcd(L_gcd[i],R_gcd[N-i-1])>ans:
        ans = gcd(L_gcd[i],R_gcd[N-i-1])
print(ans)

N = int(input())
A = list(map(int, input().split()))
M = min(A)

if M == 1:
    A.pop(1)
tmp = 1
for i in reversed(range(2,M+1)):
    count = 0
    memo = 0
    for j in range():
        if A[j]%i != 0:
            count += 1
            memo = j
            if count > 1:
                break
    if count <= 1:
        tmp = i
        break
        

print(tmp)



def gcd(a,b):
    if a <= b:
        a,b = b,a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = max(L_gcd[-1],R_gcd[0])

for i in range(N-2):
    if max(L_gcd[i],R_gcd[i+2])<=ans:
        break
    if gcd(L_gcd[i],R_gcd[i+2])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

def gcd(a,b):
    if a <= b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [0]
R_gcd = [0]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = [max(L_gcd[-2],R_gcd[1])]
for i in range(N-2):
    ans.append(gcd(L_gcd[i],R_gcd[i+2]))
print(max(ans))

N = int(input())
A = list(map(int, input().split()))
M = min(A)

if M = 1:
    A.pop(1)
tmp = 1
for i in reversed(range(2,M+1)):
    count = 0
    memo = 0
    for j in range():
        if A[j]%i != 0:
            count += 1
            memo = j
            if count > 1:
                break
    if count <= 1:
        tmp = i
        break
        

print(tmp)



N = int(input())
A = list(map(int, input().split()))
M = min(A)
tmp = 1
if M == 1:
    A.pop(1)
    if 1 in A:
        tmp = 1
    else:
        for i in reversed(range(2,M+1)):
        count = 0
        memo = 0
        for j in range(len(A)):
            if A[j]%i != 0:
                count += 1
                memo = j
                if count > 1:
                    break
        if count <= 1:
            tmp = i
            break
    

else:
    for i in reversed(range(2,M+1)):
        count = 0
        memo = 0
        for j in range(len(A)):
            if A[j]%i != 0:
                count += 1
                memo = j
                if count > 1:
                    break
        if count <= 1:
            tmp = i
            break
        

print(tmp)



def gcd(a,b):
    if a <= b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [0]*(N+1)
R_gcd = [0]*(N+1)

for i in range(N):
    L_gcd[i+1] = gcd(L_gcd[i],A[i])
    R_gcd[N-i-1] = gcd(R_gcd[N-i],A[N-i-1])

ans = 0
for i in range(N):
    if gcd(L_gcd[i],R_gcd[i+1])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+1])
    
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted