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
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

nl1.sort(reverse=True)
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])
        if r2 <= r1:
            break

    r1 = max(r1,r2)

print(str(r1))

import fractions

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

n2 = fractions.gcd(nl1[0], nl1[1])

if n1 >= 3:
    n2 = max(n2, fractions.gcd(nl1[1], nl1[2]))
    n2 = max(n2, fractions.gcd(nl1[0], nl1[2]))

c1 = 0
for i2 in range(n1):
    if nl1[i2] % n2 != 0:
        c1 += 1
    if c1 >= 2:
        break
    if i2 == (n1 - 1):
        r1 = n2

i3 = n2 // 2

while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1

print(str(r1))

import fractions
import copy
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(str(r1))

import fraction
import copy
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(r1)

import fraction
import copy
from functools import reduce

def gcd_list(numbers):
    return reduce(fraction.gcd, numbers)

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(str(r1))

import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

nl1.sort()
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])
        if r2 <= r1:
            break

    r1 = max(r1,r2)

print(str(r1))


import fractions
import sys

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

if n1 == 2:
    print(max(nl1))
    sys.exit()

r1 = 0
n2 = fractions.gcd(nl1[0], nl1[1])

if n1 >= 3:
    n2 = max(n2, fractions.gcd(nl1[1], nl1[2]))
    n2 = max(n2, fractions.gcd(nl1[0], nl1[2]))

c1 = 0
for i2 in range(n1):
    if nl1[i2] % n2 != 0:
        c1 += 1
    if c1 >= 2:
        break
    if i2 == (n1 - 1):
        r1 = n2

i3 = n2

while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1

print(str(r1))


import fractions

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

n2 = fractions.gcd(nl1[0], nl1[1])

if n1 >= 3:
    n2 = max(n2, fractions.gcd(nl1[1], nl1[2]))
    n2 = max(n2, fractions.gcd(nl1[0], nl1[2]))

c1 = 0
for i2 in range(n1):
    if nl1[i2] % n2 != 0:
        c1 += 1
    if c1 >= 2:
        break
    if i2 == (n1 - 1):
        r1 = n2

i3 = n2

while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1

print(str(r1))

import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])

    r1 = max(r1,r2)

print(str(r1))

import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])
        if r2 <= r1:
            break

    r1 = max(r1,r2)

print(str(r1))

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]
 
r1 = 0
nl1.sort()

for i5 in range(2):
    c1 = 0
    for i2 in range(n1):
        if nl1[i2] % nl1[i5] != 0:
            c1 += 1
        if c1 >= 2:
             break
        if i2 == (n1 - 1):
            r1 = nl1[i5] 
 
i3 = nl1[1] // 2
 
while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1
 
print(str(r1))

Verdicts: Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Runtime Error

Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Accepted