Problem:


Score : 300 points

Problem Statement

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.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

import numpy as np
import math

input()
A = np.array(list(set(map(int, input().split()))))
N = len(A)

if N == 1:
    print(A[0])
    exit()

sqrt_max_A = math.sqrt(max(A))
ans = 1
i = 2
while i == 2 and i <= sqrt_max_A:
    if max(A%2) == 0:
        A //= 2
        max_A = math.sqrt(max(A))
        ans *= 2
    else:
        i += 1
while i <= sqrt_max_A:
    if max(A%i) == 0:
        A //= i
        max_A = math.sqrt(max(A))
        ans *= i
    else:
        i += 2

b = 1
for i in range(N):
    li = np.concatenate([A[:i], A[i+1:]])
    
    sqrt_max_li = math.sqrt(max(li))
    tmp_ans = 1
    i = 2
    while i == 2 and i <= sqrt_max_li:
        if max(li%2) == 0:
            li //= 2
            max_li = math.sqrt(max(li))
            tmp_ans *= 2
        else:
            i += 1
    while i <= sqrt_max_li:
        if max(li%i) == 0:
            li //= i
            max_li = math.sqrt(max(li))
            tmp_ans *= i
        else:
            i += 2
    
    b = max(b, tmp_ans)

print(ans*b)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
            n /= i  

    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(a1_miss[:]):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
if A[0] == 1 and A[1] == 1:
    print(1)

elif A[0] == 1:
    del A[0]
    for index, x in enumerate(A):

        if index  == 0:
            a = yakusu(A[0])
        elif index == 1:
            a1_miss, a = yakusu1(A[1], a)
        else:
            a1_miss, a = yakusu2(A[index], a1_miss, a)
    if len(a) != 0:
        for i in a:
            value *= i
    

else:
    for index, x in enumerate(A):
        if index  == 0:
            a = yakusu(A[0])
        elif index == 1:
            a1_miss, a = yakusu1(A[1], a)
        else:
            a1_miss, a = yakusu2(A[index], a1_miss, a)
    value = 1
    if len(a) != 0:
        for i in a:
            value *= i
    if len(a1_miss) != 0:
        for i in a1_miss:
            value *= i
    print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 1
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                if i != 1:
                    break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
            n /= i  

    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(a1_miss[:]):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
if len(a) != 0:
    for i in a:
        value *= i
if len(a1_miss) != 0:
    for i in a1_miss:
        value *= i
print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
            n /= i  

    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(a1_miss[:]):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
if len(a) != 0:
    for i in a:
        value *= i
if len(a1_miss) != 0:
    for i in a1_miss:
        value *= i
print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
            n /= i  

    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(a1_miss[:]):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
for i in a1_miss:
    value *= i
    print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
            n /= i  

    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    b = a1_miss[:]
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(b):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
if len(a1_miss) != 0:
    print(value*max(a1_miss))
else:
    print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    b = a1_miss[:]
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(b):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
if len(a1_miss) != 0:
    print(value*max(a1_miss))
else:
    print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
            n /= i
    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    b = a1_miss[:]
    nex = 0
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(b):
        if n % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
if len(a1_miss) != 0:
    print(value*max(a1_miss))
else:
    print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    b = a1_miss[:]
    nex = 0
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(b):
        if n % i != 0:
            del a1_miss[index-nex]
            nex += 1
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
if len(a1_miss) != 0:
    print(value*max(a1_miss))
else:
    print(value)

Submission status: Wrong Answer

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
    return a1, a2
    
def yakusu2(n, a1_miss, a):
    b = a1_miss[:]
    nex = 0
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            a1_miss.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(b):
        if n % i != 0:
            del a1_miss[index-nex]
            nex += 1
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
if len(a1_miss) != 0:
    print(value*max(a1_miss))
else:
    print(value)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))


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


ans = [0] * n
lileft = [0] * (n + 1)
liright = [0] * (n + 1)
for i in range(n):
    lileft[i + 1] = gcd(lileft[i], li[i])
for i in range(n):
    liright[i + 1] = gcd(liright[i], li[i])
for i in range(n):
    ans[i] = gcd(lileft[i], liright[i])
print(max(ans))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], A[N - i - 1]))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[0]
	elif i == N - 1:
		ans = L[-1]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], N - i))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[1]
	elif i == N - 1:
		ans = L[-2]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], N - i))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[0]
	elif i == N - 1:
		ans = L[-1]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], N - i))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[1]
	elif i == N - 1:
		ans = L[-1]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], N - i))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[1]
	elif i == N - 1:
		ans = L[1]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
divisor = []

for a in A:
	#ある数aについての処理
	for i in range(a // 2, 0, -1):
		if a % i == 0:
			divisor.append(i)

maximum = max(A)
total = [0] * maximum
for i in divisor:
	total[i] += 1
	
for i in range(maximum - 1, 0, -1):
	if total[i] == N - 1:
		print(i)
		break

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
divisor = []

for a in A:
	#ある数aについての処理
	divisor.append(a)
	for i in range(a // 2, 0, -1):
		if a % i == 0:
			divisor.append(i)

maximum = max(A)
for i in range(maximum, 0, -1):
	if divisor.count(i) == N - 1:
		print(i)
		break

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
divisor = []

for a in A:
	#ある数aについての処理
	divisor.append(a)
	for i in range(a // 2, 0, -1):
		if a % i == 0:
			divisor.append(i)

for i in range(1, max(A) + 1):
	if divisor.count(i) == N - 1:
		print(i)

Submission status: Wrong Answer

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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i]))
r.append(0)
r.append(A[-1])
for i in range(1,N-1):
    r.append(fr.gcd(r[i],A[-i-1]))
print(l,r)
ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)

Submission status: Wrong Answer

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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i+1]))
r.append(A[-1])
for i in range(N-1):
    r.append(fr.gcd(r[i],A[-i-1]))

ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)

Submission status: Wrong Answer

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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i+1]))
r.append(0)
r.append(A[-1])
for i in range(1,N-1):
    r.append(fr.gcd(r[i],A[-i-1]))

ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(x) for x in input().split()]

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

dp = [0]*N

for i,e in enumerate(A):
  if i > 0:
    x = max(0,i-N)
    dp[i] = max([d+gcd(e,ht) for d, ht in zip(dp[x:i], A[x:i])])
    
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import fractions

def multiple_gcd(a):
  ans = a[0]
  for i in range(1, len(a)):
      ans = fractions.gcd(ans, a[i])
  return(ans)

N = int(input())
A = [int(i) for i in input().split()]

answer = 0
for i in range(len(A) - 1):
  gcd = multiple_gcd(A[:i] + A[i + 1:]) 
  answer = max(answer, gcd)

print(answer)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

n = int(input())
a = list(map(int,input().split()))

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(fractions.gcd, a_except_for_i))
    
    if len(l) > 1 and l[i] == l[i - 1]:
        break
print(max(l))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int,input().split()))

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
a = [int(i) for i in input().split()]

L = []
R = []
L.append(a[0])
R.append(a[-1])

for i in range(N-2):
    L.append(gcd(L[-1], a[i+1]))
    R.append(gcd(R[-1], a[-(i+2)]))

print(L)
print(R)
ans = max(L[-1], R[-1])
for i in range(N-2):
    tmp = gcd(L[i], R[-(i+2)])
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(n//2+1):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(a[n-i-1],r[i]))

#print(l,r)
ans = 0
for i in range(min(len(l),len(r))):
    ans = max(ans,gcd(l[i],r[len(r)-i-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(n//2+1):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(a[n-i-1],r[i]))
if l[-1] != r[-1]:
    print(max(l[-1],r[-1]))
else:
    print(gcd(l[-2],r[-2]))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))

if n==2:
    b=max(a)
else:
    s1=gcd(a[0],a[1])
    s2=gcd(a[0],a[2])
    s3=gcd(a[2],a[1])
    c=gcd(s1,s2)
    b=max(s1,s2,s3)
    if b==s1:
        t=a[2]
    elif b==s2:
        t=a[1]
    else:
        t=a[0]
    if len(a)>=4:
        for i in a[3:]:
            d=gcd(b,i)
            if d>c:
                b=d
                c=gcd(c,i)
            else:
                t=i
                b=c
                c=d
print(b)

Submission status: Wrong Answer

Solution code:
def larger(x, y):
	if x > y: return x
	return y

def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)

N = int(input())
A = list(map(int, input().split()))
left = [A[0]]
for i in range(1, N):
	left.append(euc(left[-1], A[i]))
right = [A[-1]]
for i in range(1, N):
	right.append(euc(right[-1], A[-1-i]))
right.reverse()

max = larger(left[N-2], right[N-2])
for i in range(1, N-1):
	max = larger(max, euc(left[i-1], right[i+1]))
print(max)

Submission status: Wrong Answer

Solution code:
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
gcd = [A[0]]
for i in range(1, N):
	gcd.append(euc(gcd[-1], A[i]))
index = -1
min = 5000000000000000
for i in range(0, N):
	if gcd[i] < min:
		min = gcd[i]
		index = i
A.pop(index)
ans = A[0]
for i in range(0, len(A)):
	ans = euc(ans, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from functools import reduce
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

n=int(input())

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

left=[0]*(n+1)
right=[0]*(n+1)

left[1]=a[0]
right[n-1]=a[n-1]

for i in range(1,n):
    left[i+1]=gcd(left[i],a[i])
    right[n-1-i]=gcd(right[n-i],a[n-i-1])

# print(left)
# print(right)
last=[0]*n
last[0]=right[1]

for i in range(1,n-1):
    last[i]=(gcd(left[i],right[n-i]))

last[n-1]=left[n]

print(max(last))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from functools import reduce
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

n=int(input())

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

left=[0]*(n+1)
right=[0]*(n+1)

left[1]=a[0]
right[n-1]=a[n-1]

for i in range(1,n):
    left[i+1]=gcd(left[i],a[i])
    right[n-1-i]=gcd(right[n-i],a[n-i-1])

# print(left)
# print(right)
last=[0]*n
last[0]=right[1]

for i in range(1,n-1):
    last.append(gcd(left[i],right[n-i]))

last[n-1]=left[n-1]

print(max(last))

Submission status: Wrong Answer

Solution code:
import fractions
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
acc_gcd = fractions.gcd(data[0],data[1])
for i in data:
    acc_gcd = fractions.gcd(acc_gcd,i)
print(acc_gcd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=[int(i) for i in input().split()]
l=r=[0]*(n+1)
for i in range(n):
    l[i+1]=gcd(l[i],a[i])
    r[n-i-1]=gcd(r[n-i],a[n-i-1])
x=[]
for i in range(n):
    x.append(gcd(l[i],r[i+1]))
print(max(x))

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
forward = [0]
back =[0]
for i in range(0,n-1):
    forward.append(fractions.gcd(forward[i], a[i]))
    back.append(fractions.gcd(back[i], a[n-i-1]))

back.reverse()

ans = max(forward[n-2], back[0])
for i in range(n-2):
    ans = max(ans, fractions.gcd(forward[i], back[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
forward = [0, a[0]]
back =[0, a[n-1]]
for i in range(1,n-1):
    forward.append(fractions.gcd(forward[i], a[i]))
    back.append(fractions.gcd(back[i], a[n-i-1]))
print(forward)
back.reverse()
print(back)
ans = max(forward[n-2], back[0])
for i in range(n-2):
    ans = max(ans, fractions.gcd(forward[i], back[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
forward = [a[0]]
back =[a[n-1]]
for i in range(n-2):
    forward.append(fractions.gcd(forward[i], a[i+1]))
    back.append(fractions.gcd(back[i], a[n-i-2]))

ans = max(forward[n-2], back[n-2])
for i in range(n-2):
    ans = max(ans, fractions.gcd(forward[i], back[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

r1 = 0

n2 = min(nl1)

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))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    GCD = [0 for _ in range(N)]

    res = 0
    for i in range(N):
        l = gcd_list(A[:i])
        r = gcd_list(A[i+1:])
        res = max(res, gcd(l, r))
    print(res)


def gcd_list(l):
    if len(l) == 1:
        return l[0]
    m = 0
    for i in range(len(l)-1):
        m = max(m, gcd(l[i], l[i+1]))
    return m


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

main()

Submission status: Wrong Answer

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

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

L = [0]; R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[N-1-i]))

maxGCD = 1
for j in range(N):
    maxGCD = max(maxGCD, gcd(L[i], R[N-i-1]))
print(maxGCD)

Submission status: Wrong Answer

Solution code:
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()

ans = rev_accumulation_gcd[1]

for i in range(1, n-1):
    ans = max(ans, f.gcd(accumulation_gcd[i-1], rev_accumulation_gcd[i+1]))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
nums = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
    divs = []
    if n == 1: return 1
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs
ans = 1
if len(nums) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums[0])
    divs2 = compute_divs(nums[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in range(len(nums)):
            if nums[j] % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n=int(input())
a=list(map(int,input().split()))

L=[0 for i in range(n)]
R=[0 for i in range(n)]

for i in range(n-1):
  L[i+1]=gcd(L[i],a[i])
for i in range(n-2,-1,-1):
  R[i]=gcd(R[i+1],a[i+1])

M=[gcd(L[i],R[i]) for i in range(n-1)]

print(max(M))