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:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = []
l = 0
for skip in range(1, N+1):
    l = GCD(l, A[skip-1])
    r = 0
    for i in range(skip+1, N):
        r = GCD(r, A[i])
    n = GCD(l, r)
#   print(l,r,n)
    result.append(n)
print(max(result))

Submission status: Wrong Answer

Solution code:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = []
l = 0
for skip in range(1, N):
    r = 0
    l = GCD(l, A[skip-1])
    for i in range(skip+1, N):
        r = GCD(r, A[i])
    n = GCD(l, r)
#   print(l,r,n)
    result.append(n)
print(max(result))

Submission status: Wrong Answer

Solution code:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    print(a, b)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = []
for skip in range(N):
    l = 0
    r = 0
    for v in range(0, skip): l = GCD(l, A[v])
    for v in range(N-1, skip, -1): r = GCD(r, A[v])
    result.append(GCD(l, r))

print(max(result))

Submission status: Wrong Answer

Solution code:
# 1行目を取得
a = int(input())
# 2行目をリストの形で取得
b = list(input().split())

# 最大公約数を格納する箱を作成
common_divisor = 0

# リストの要素分処理を繰り返す。
for i in range(a):
    test = 0
    # リストのn,n+1個目の要素の差を算出する。
    try:
        test_common_divisor = abs(int(b[i]) - int(b[i+1]))

        # リストに含まれる要素それぞれを上記で求めた差で割り算し、割り切れる要素の数をカウント
        for y in range(a):
            # あまりがゼロだった場合は何もしない
            if int(b[y]) % test_common_divisor == 0:
                pass
            # あまりが1以上だった場合は、test の中を加算する。
            else:
                test += 1

        # もしtest が1以上だった場合は何もしない、test が0だった場合は最大公約数の中にテスト最大公約数をいれる。
        if int(test) > 1:
            pass
        else:
            common_divisor = test_common_divisor

    except:
        pass


print(common_divisor if common_divisor > 0 else 1)

Submission status: Wrong Answer

Solution code:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

a = []
for i in range(N - 1):
    a.append( GCD(A[i], A[i+1]) )
a.append( GCD(A[0], A[-1]) )
print(max(a))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
l = list(map(int, input().strip().split()))
maxe = 0
     
for i in range(n):
    for j in range(n):
        if i != j:
            g = gcd(l[i],l[j])
            maxe = max(maxe, g)
print(maxe)

Submission status: Wrong Answer

Solution code:
num =int(input())
value = list(map(int, input().split()))
value.sort()
for i in range (0, value[0]):
  cnt = 0
  for j in range(0, num):
    if value[j]%(value[0]-i)!=0:
      cnt += 1
      if cnt == 2:
        break
  if cnt == 1 or cnt == 0:
    break
print(value[0] - i)

Submission status: Wrong Answer

Solution code:
num =int(input())
value = list(map(int, input().split()))
value.sort()
for i in range (0, value[0]):
  cnt = 0
  for j in range(0, num):
    if value[j]%(value[0]-i)!=0:
      cnt += 1
  if cnt == 1 or cnt == 0:
    break
print(value[0] - i)

Submission status: Wrong Answer

Solution code:
num =int(input())
value = list(map(int, input().split()))
value.sort()
point = 0
for i in range (0, value[0]):
  cnt = 0
  for j in range(0, num):
    if value[j]%(value[0]-i)!=0:
      cnt += 1
      point = j
  print(i)
  if cnt == 1 or cnt == 0:
    break
print(value[0] - i)

Submission status: Wrong Answer

Solution code:
num =int(input())
value = list(map(int, input().split()))
value.sort()
point = 0
for i in range (0, value[0]):
  cnt = 0
  for j in range(0, num):
    if value[j]%(value[0]-i)!=0:
      cnt += 1
      point = j
  if cnt == 1:
    value[point] = value[0] - i
    break
print(value[0] - i)

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())
l=list(map(int, input().split()))
ml=[]
for i in range(n):
  for j in range(n):
    if i != j:
      ml.append(fractions.gcd(l[i], l[j]))
    else:
      break
    
print(max(ml))

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())
l=list(map(int, input().split()))
ml=[]
for i in range(n):
  for j in range(n):
    if i != j:
    	ml.append(fractions.gcd(l[i], l[j]))
    
print(max(ml))

Submission status: Wrong Answer

Solution code:
# --*-- coading: utf-8 --*--
def gcd(a,b):
    l,s = max(a,b), min(a,b)
    r = l % s        
    while r != 0:
        l = s
        s = r
        r = l % s
    return s


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

temp=[0]*(N-1)
temp[0]=gcd(Ai[0],Ai[1])

for ii in range(1, N-1):
    temp[ii] = gcd(temp[ii-1],Ai[ii])

print(max(temp))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = []
for i in range(N):
    X = A[:i] + A[i+1:]
    for v in range(10000, 0, -1):
        if all([x % v == 0 for x in X]):
                   M.append(v)
                   break
print(max(M))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

bwd = [A[-1]]
for i in range(N-2, -1, -1):
    bwd.append(gcd(bwd[-1], A[i]))

gmax = max(fwd[-2], bwd[1])
for i in range(1, N-1):
    gmax = max(gmax, gcd(fwd[i-1], bwd[i+1]))

print(gmax)

Submission status: Wrong Answer

Solution code:
def gcd(n1,n2):
    if n1 < n2:
        big = n2
        sma = n1
    else:
        big = n1
        sma = n2
    c = big // sma
    d = big % sma
    while d > 0:
        big = sma
        sma = d
        c = big // sma
        d = big % sma
    return sma
        
n = int(input())
li = [int(i) for i in input().split()]
gc1 = [1]*(n-1)
gc2 = [1]*(n-1)
gc1[0] = li[0]
gc2[0] = li[n-1]
ma = 1
for i in range(len(li)-2):
    gc1[i+1] = gcd(gc1[i],li[i+1])
    gc2[i+1] = gcd(gc2[i],li[n-2-i])
if ma < gc1[n-2]:
    ma = gc1[n-2]
if ma < gc2[n-2]:
    ma = gc2[n-2]
for i in range(len(li)-2):
    m = gcd(gc1[i],gc2[n-2-i])
    if ma < m:
        ma = m
print(ma)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import numpy as np

N = int(input())
A_array = [int(A_i_str) for A_i_str in set(input().split())]
if len(A_array) == 1:
  print(A_array[0])
  exit()

scores = [0 for i in range(len(A_array))]
gcds = {}
for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    A_max = max(A_i, A_j)
    A_min = min(A_i, A_j)
    idx = (A_min, A_max)

    if idx in gcds:
      gcd = gcds[idx]
    else:
      gcd = fractions.gcd(A_i, A_j)
      gcds[idx] = gcd

    scores[i] = scores[i] + gcd
    scores[i + j + 1] = scores[i + j + 1] + gcd

min_score = scores[0]
min_score_idx = 0
for i, score in enumerate(scores):
  if score < min_score or (score == min_score and A_array[i] < A_array[min_score_idx]):
    min_score = score
    min_score_idx = i

A_array.pop(min_score_idx)
print(functools.reduce(fractions.gcd, A_array))

Submission status: Wrong Answer

Solution code:
# from math import gcd

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 

def cR(A, i):
    if i == len(A):
        return 0
    else:
        g = 0
        for i in range(i, len(A)):
            g = gcd(g, A[i])
        return g

def cL(A, i):
    if i == 1:
        return 0
    else:
        g = 0
        for i in range(i+1):
            g = gcd(g, A[i])
        return g


n = int(input())
A = list(map(int, input().split()))
A.append(0)
R = [0] * (n+2)
L = [0] * (n+2)
M = [0] * (n+2)

g = A[n-1]
for i in range(n-1, -1, -1):
    R[i] = gcd(g, A[i])

g = A[0]
for i in range(1,n+1):
    L[i] = gcd(g, A[i-1])

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

# print(L, R, M)
print(max(M))

Submission status: Wrong Answer

Solution code:
# from math import gcd

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 

def cR(A, i):
    if i == len(A):
        return 0
    else:
        g = 0
        for i in range(i, len(A)):
            g = gcd(g, A[i])
        return g

def cL(A, i):
    if i == 1:
        return 0
    else:
        g = 0
        for i in range(i+1):
            g = gcd(g, A[i])
        return g


n = int(input())
A = list(map(int, input().split()))
A.append(0)
R = [0] * (n+2)
L = [0] * (n+2)
M = [0] * (n+2)

g = A[n-1]
for i in range(n-1, -1, -1):
    R[i] = gcd(g, A[i])

g = A[0]
for i in range(1,n+1):
    L[i] = gcd(g, A[i-1])

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

# print(L, R, M)
print(max(M))

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import numpy as np

N = int(input())
A_array = [int(A_i_str) for A_i_str in input().split()]

scores = [0 for i in range(N)]
gcds = {}
for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    A_max = max(A_i, A_j)
    A_min = min(A_i, A_j)
    idx = (A_min, A_max)
    gcd = gcds[idx] if idx in gcds else fractions.gcd(A_i, A_j)
    scores[i] = scores[i] + gcd
    scores[i + j + 1] = scores[i + j + 1] + gcd
    if not idx in gcds:
      gcds[idx] = gcd

A_array[np.argmin(scores)] = A_array[np.argmax(scores)]
print(functools.reduce(fractions.gcd, A_array))

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import numpy as np

N = int(input())
A_array = [int(A_i_str) for A_i_str in input().split()]

scores = [0 for i in range(N)]
for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    gcd = fractions.gcd(A_i, A_j)
    scores[i] = scores[i] + gcd
    scores[i + j + 1] = scores[i + j + 1] + gcd

A_array[np.argmin(scores)] = A_array[np.argmax(scores)]
print(functools.reduce(fractions.gcd, A_array))

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import numpy as np

N = int(input())
A_array = sorted([int(A_i_str) for A_i_str in input().split()])

scores = [0 for i in range(N)]
for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    gcd = fractions.gcd(A_i, A_j)
    scores[i] = scores[i] + gcd
    scores[i + j + 1] = scores[i + j + 1] + gcd

A_array[np.argmin(scores)] = A_array[np.argmax(scores)]
print(functools.reduce(fractions.gcd, A_array))

Submission status: Wrong Answer

Solution code:
import fractions
import functools

N = int(input())
A_array = sorted([int(A_i_str) for A_i_str in input().split()])

min_gcd = max(A_array)
min_gcd_idx = 0
max_gcd = 0
max_gcd_idx = 0

for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    gcd = fractions.gcd(A_i, A_j)
    print("gcd: " + str(gcd))
    if gcd <= min_gcd:
      min_gcd = gcd
      min_gcd_idx = i
    elif gcd >= max_gcd:
      max_gcd = gcd
      max_gcd_idx = i + j + 1

A_array[min_gcd_idx] = A_array[max_gcd_idx]
print(functools.reduce(fractions.gcd, A_array))

Submission status: Wrong Answer

Solution code:
import fractions
import functools

N = int(input())
A_array = sorted([int(A_i_str) for A_i_str in input().split()])

min_gcd = max(A_array)
min_gcd_idx = 0
max_gcd = 0
max_gcd_idx = 0

for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    gcd = fractions.gcd(A_i, A_j)
    print("gcd: " + str(gcd))
    if gcd <= min_gcd:
      min_gcd = gcd
      min_gcd_idx = i
    elif gcd >= max_gcd:
      max_gcd = gcd
      max_gcd_idx = i

A_array[min_gcd_idx] = A_array[max_gcd_idx]
print(functools.reduce(fractions.gcd, A_array))

Submission status: Wrong Answer

Solution code:
def gcd(n1,n2):
    if n1 < n2:
        big = n2
        sma = n1
    else:
        big = n1
        sma = n2
    c = big // sma
    d = big % sma
    while d > 0:
        big = sma
        sma = d
        c = big // sma
        d = big % sma
    return sma
        
n = int(input())
li = [int(i) for i in input().split()]
gc = 1
gc1 = [1]*(n-1)
gc2 = [1]*(n-1)
gc1[0] = li[0]
gc2[0] = li[n-1]
for i in range(len(li)-2):
    gc1[i+1] = gcd(gc1[i],li[i+1])
    gc2[i+1] = gcd(gc2[i],li[n-i-2])
ma = 1
for i in range(len(li)-1):
    ma1 = gcd(gc1[i],gc2[n-i-2])
    if ma1 > ma:
        ma = ma1
print(ma)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lgcd, rgcd = [], []
for i in range(n):
    if i == 0:
        lgcd.append(a[0])
        rgcd.append(a[n-1])
        continue

    lgcd.append(gcd(lgcd[i-1], a[i]))
    rgcd.append(gcd(rgcd[i-1], a[-1-i]))

maxgcd = 1
for i in range(n):
    if i == 0:
        tempgcd = rgcd[n-1]
    elif i == n-1:
        tempgcd = lgcd[n-1]
    else:
        tempgcd = gcd(lgcd[i-1], rgcd[n-2-i])
    maxgcd = max(maxgcd, tempgcd)
print(maxgcd)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    else:
        return x

N=int(input())
A=[int(i) for i in input().split()]
GCD=[]
if len(A)==2:
    print(gcd(A[0],A[1]))
else:
    for i in range(N):
        B=A.copy()
        B.remove(B[i])
    
        a=gcd(B[0],B[1])
        for k in range(N-3):
            a=gcd(a,B[k+2])
        GCD.append(a)
    print(max(GCD))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
  while(y): 
       x, y = y, x % y   
  return x 

def solve():
  n = 3
  a = [7, 6, 8]
  left = [0] * (n + 1)
  right = [0] * (n + 1)
  for i in range(1,n + 1):
    left[i] = gcd(left[i - 1], a[i - 1])
  for i in range(n - 1, 0, -1):
    right[i] = gcd(right[i + 1], a[i])
  max_gcd = 0
  for i in range(n):
    max_gcd = max(max_gcd, gcd(left[i], right[i]))
  print max_gcd
        
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() ) # <= 10^5
A = list( map( int, input().split() ) ) # <= 10^9


"""
i番目の数を変更するとすると求めるべき最大公約数はi番目の数を除いた残りの数の最大公約数である
"""

"""
# i = 0 の場合
g = A[1]
g = gcd( g, A[2] )
g = gcd( g, A[3] )
...
g = gcd( g, A[N - 1] ) = R(0)

iを消すとして
iの左側の最大公約数をL(i) (0~i-1の最大公約数)
iの右側の最大公約数をR(i) (i+1からN-1の最大公約数)

i + 1 ~ N - 1
0 ~ N - 1 - (i + 1)

とするとiを消した時の求めるべき最大公約数は
gcd( L(i), R(i) )
であり
L(i + 1) = gcd( L(i), A[i] )
R(i)     = gcd( R(i + 1), A[i] )
という関係が成り立つ
ここで
L(0) = R(N-1) = 0
gcd(0, X) = X
と定義する

L_0を求めて残りは漸化式より順に求める
R_N-1を求めて残りは漸化式より順に求める
"""
def gcd(x, y):
    if x == 0:
        return y
    
    if y == 0:
        return x

    return fractions.gcd(x, y)

# def L(i):
#     if i == 0:
#         return 0
    
#     g = 0
#     for t in range(i):
#         g = gcd( g, A[t] )
#     return g

# def R(i):
#     if i == N - 1:
#         return 0
    
#     g = 0
#     for t in range(N - i - 1):
#         g = gcd( g, A[i + 1 + t] )
#     return g

G = [0] * N # i番目の要素はA_iを除いた時の最大公約数

L_buf = 0
R_buf = 0
tmp1 = 0
tmp2 = 0

for i in range(N):
    if i == 0:
        G[0] = L_buf
        G[N-1] = R_buf
        continue

    tmp1 = gcd( L_buf, A[i-1] )
    # G[i] = G[i] + tmp1
    G[i] = gcd(G[i], tmp1)
    L_buf = tmp1

    tmp2 = gcd( R_buf, A[N - 1 - i + 1] )
    # G[N - 1 - i] = G[N - 1 - i] + tmp2
    G[N - 1 - i] = gcd(G[N - 1 - i], tmp2)
    R_buf = tmp2
    print(tmp1, tmp2)

print(max(G))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
if len(a) < 3:
    print(gcd(a[0], a[1]))
    exit()
l = list(accumulate(a, func=gcd))
r = list(accumulate(reversed(a), func=gcd))
print(max([gcd(l[i - 1], r[i - 1]) for i in range(1, n - 1)] + [l[1], r[1]]))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
if len(a) < 3:
    print(gcd(a[0], a[1]))
    exit()
l = list(accumulate(a, func=gcd))
r = list(accumulate(reversed(a), func=gcd))
print(max(l[len(l) - 2], r[len(r) - 2], max([gcd(l[i - 1], r[i - 1]) for i in range(1, n - 1)])))

Submission status: Wrong Answer

Solution code:
import fractions

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

gcd_r=[0]*n
gcd_r[n-1]=a[n-1]
for i in range(n-2,-1,-1):
  gcd_r[i]=fractions.gcd(gcd_r[i+1],a[i])
#gcd_r[i]は末尾からa[i]までのgcd

gcd_l=[0]*n
gcd_l[0]=a[0]
for i in range(1,n):
  gcd_l[i]=fractions.gcd(gcd_l[i-1],a[i])
#gcd_l[i]は先頭からa[i]までのgcd

ans=gcd_r[1]
for i in range(1,n-1):
  ans=max(fractions.gcd(gcd_l[i-1],gcd_r[i+1]),ans)
print(max(ans,gcd_l[n-1]))

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):
    B = A[:]
    B.pop(i)
    print(B)
    l.append(reduce(fractions.gcd, B))
    
print(max(l))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, A))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

N = 3
A = [7, 6, 8]

print(reduce(fractions.gcd, A))

Submission status: Wrong Answer

Solution code:
N = int(input())
li = [ int(it) for it in input().split() ]
lil = [0]*N
lir = [0]*N

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
lil[0]=li[0]
lir[N-1]=li[N-1]
for i in range(N-1):
  lil[i+1]=gcd(li[i+1],lil[i])
for i in range(N-1,0,-1):
  lir[i-1]=gcd(li[i-1],lir[i])
s = -1
for i in range(N):
  if (i==0):
    gc = lil[1]
  elif (i==N-1):
    gc = lir[N-2]
  else:
    gc = gcd(lil[i-1],lir[i+1])
  s = max(s, gc )
print (s)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a<b:
        a,b = b,a
    if b==0:
        return a
    c = a%b
    return gcd(b,c)
n = int(input())
a = list(map(int,input().split()))
right,left = [0 for i in range(n)],[0 for i in range(n)]
right[0],left[n-1] = a[0],a[n-1]
for i in range(1,n):
    right[i] = gcd(right[i-1],a[i])
for i in range(n-2,-1,-1):
    left[i] = gcd(left[i+1],a[i])
ans = max(left[n-2],right[1])
for i in range(1,n-1):
    ans = max(ans,gcd(left[i+1],right[i-1]))
print(ans)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int,input().split()))
right,left = [0 for i in range(n)],[0 for i in range(n)]
right[0],left[0] = a[0],a[-1]
for i in range(1,n):
    right[i] = gcd(right[i-1],a[i])
    left[i] = gcd(left[i-1],a[n-i-1])
ans = max(left[n-2],right[n-2])

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

Submission status: Wrong Answer

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

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x


if N <= 2:
  print(max(A))
else:
  max = 0
  for i in range(N):
    temp = A.pop(0)
    ans = gcd(A[0], A[1])
    for j in A[1:]:
      ans = gcd(ans, j)
    if max < ans:
      max = ans
    A.append(temp)
  print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

dic = {}
for i, x in enumerate(a):
    print(i)
    if i <2:
        for y in make_divisors(x):
            if y in dic:
                dic[y] += 1
            else:
                dic[y] = 1
    else:
        l = make_divisors(x)
        for k,v in dic.items():
            if k in l:
                dic[k]+=1

        dic = {k:v for k,v in dic.items() if v>i-1}
        
for k,v in sorted(dic.items(), reverse=True):
    print(k)
    exit()

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions as fr

def gcd(a):
  ua = np.unique(a)
  if ua.size == 1:
    return ua[0]
  
  if ua.size == 2:
    gcd = fr.gcd(ua[0],ua[1])
    if gcd == 0:
      return ua.max()
    else:
      return gcd

  gcd1 = fr.gcd(ua[0],ua[ua.size-1])
  gcd2 = fr.gcd(ua[0],ua[ua.size-2])
  gcd3 = fr.gcd(ua[ua.size-1],ua[ua.size-2])

  if gcd1 == gcd2 == gcd3:
    return gcd1
  
  gcds = [gcd1,gcd2,gcd3]
  gcds.sort()
  gcds.reverse()
  if np.sum(ua % gcds[0] == 0) == ua.size-1:
  	return gcds[0]
  if np.sum(ua % gcds[1] == 0) == ua.size-1:
  	return gcds[1]
  
  return gcds[2]
    
n = int(input())
a = np.array([_ for _ in map(int,input().split())])

print(gcd(a))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if a > b:
        return gcd(b, a)
    else:
        if a == 0:
            return b
        else:
            return gcd(b % a, a)
N=int(input())
s=list(map(int,input().split()))

if N==2:
       print(max(s))

ans_l=[]
i=0
while i<N:
       j=0
       while j<N:
              p=0
              if i!=j:
                     p=gcd(s[i],s[j])
                     ans_l.append(p)
              j+=1
       
       i+=1
print(max(ans_l))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
T=0
for i in a[1:]:
    T=k(i,T)

L=[0 for i in range(n-1)]
R=[0 for i in range(n-1)]
a.sort()
for i in range(n-1):
    L[i]=k(a[i],L[i-1])
a=list(reversed(a))
for i in range(n-1):
    R[i]=k(a[i],R[i-1])
ans=[k(L[i],R[i]) for i in range(n-1)]
ans+=[T]

print(max(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
T=0
for i in a[1:]:
    T=k(i,T)

L=[0 for i in range(n)]
R=[0 for i in range(n)]
a.sort()
for i in range(n-1):
    L[i]=k(a[i],L[i-1])

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

ans=[k(L[i],R[i]) for i in range(n)]
ans+=[T]

print(max(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
TT=0
for i in a[:-1]:
    TT=k(i,TT)
ans+=[TT]
L=[0 for i in range(n)]
R=[0 for i in range(n)]
for i in range(n-2):
    L[i]=k(a[i],L[i-1])
    R[i]=k(a[i+2],R[i-1])
    ans+=[k(L[i],R[i])]
print(max(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
L=[0 for i in range(n)]
R=[0 for i in range(n)]
for i in range(n-1):
    L[i]=k(a[i],L[i-1])
    if i+2>=n:
        pass
    else:
        R[i]=k(a[i+2],R[i-1])
    ans+=[k(L[i],R[i])]
print(max(ans))

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int,input().split()))
res = []
for i in range(0,n):
    for j in range(0,n):
        if i != j:
            res.append(gcd(a[i],a[j]))
print(max(res))

Submission status: Wrong Answer

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


n = int(input())
a = map(int,input().split())
a = list(map(int, a))
a1 = a
res = 0
count = 0
count1 = 0
for i in a:
    for j in a1:
        if count != count1 and gcd(i,j)>res:
            res = gcd(i,j)
        count1 = count1 + 1
    count = count + 1
    count1 = 0
print(res)

Submission status: Wrong Answer

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


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

gcd_l = [0] * N

gcd_l[0] = A[0]
for i in range(1, N):
    gcd_l[i] = gcd(gcd_l[i - 1], A[i])

gcd_r = [0] * N

gcd_r[N - 1] = A[N - 1]
for i in reversed(range(0, N - 1)):
    gcd_l[i] = gcd(gcd_r[i + 1], A[i])

gcd_lr = [0] * N

for i in range(N):
    if i == 0:
        gcd_lr[i] = gcd_r[i + 1]
    elif 1 <= i <= N - 2:
        gcd_lr[i] = gcd(gcd_l[i - 1], gcd_r[i + 1])
    elif i == N - 1:
        gcd_lr[i] = gcd_l[i - 1]

print(max(gcd_lr))

Submission status: Wrong Answer

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

n=int(input())
a_array=[int(a) for a in input().split()]

left_gcd=[a_array[0]] # 
a=a_array[0]
for i in range(1, n-1):
    a=gcd(a,a_array[i])
    left_gcd.append(a)

right_gcd=[a_array[-1]]
b=a_array[-1]
for i in range(n-2,0,-1):
    b=gcd(b,a_array[i])
    right_gcd.append(b)

ans_gcd=[right_gcd[n-2],left_gcd[n-2]]

for i in range(n-2):
    ans_gcd.append(gcd(left_gcd[i],right_gcd[n-i-3]))

Submission status: Wrong Answer

Solution code:
import functools
import fractions

N = 3
A = [12, 15, 18]
answer = 0
for i in range(N):
  tmp = A.copy()
  tmp.pop(i)
  gcd = functools.reduce(fractions.gcd, tmp)
  
  if answer < gcd:
    answer = gcd

print(int(answer))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import itertools

n = int(input())
nums = sorted(list(map(int, input().split())))

gcds = {}
for pair in itertools.combinations(nums, 2):
    gcds[tuple(pair)] = gcd(*pair)

gcds = sorted(set(gcds.values()))
if len(gcds) > 1:
    print(gcds[1])
else:
    print(gcds[0])

Submission status: Wrong Answer

Solution code:
import copy
import fractions
from functools import reduce


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


n = int(input())
a = list(map(int, input().split()))
gcdli = []
for i in range(n - 1):
    a_copy = copy.deepcopy(a)
    a_copy.pop(i)
    gcdli.append(gcd_list(a_copy))
print(max(gcdli))

Submission status: Wrong Answer

Solution code:
import math
import functools
import fractions
from functools import reduce
import itertools

gcd1 = 0
gcd2 = 0
ans = 0

N = int(input())
values = ([int(x) for x in input().split()])
for i in list(itertools.combinations(values,2)):
  gcd1 = functools.reduce(fractions.gcd,i)
  if gcd1>gcd2:
    gcd2 = gcd1
    ans = gcd1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    ai=a[:i]+a[i+1:]
    while len(ai)>1:
        ai.append(fractions.gcd(ai.pop(),ai.pop()))
        if min(ai)<ans or min(ai)==1:break
    ans=max(ans,ai[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as frac
from functools import reduce

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

def gcd_with_replace(numbers, replace_index) :
    numbers = numbers[:]
    numbers[replace_index] = 0
    return gcd_list(numbers)

def main() :
    N = int(input())
    A_list = [int(i) for i in input().split()]
    A_list.reverse()
    max_gcd_value = 0
    for i in range(N) :
        gcd_value = gcd_with_replace(A_list,i)
        if (max_gcd_value < gcd_value) :
            max_gcd_value = gcd_value
    
    print(gcd_value)



main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
x=0
y=0
z=0
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
TT=0
for i in a[:-1]:
    TT=k(i,TT)

ans=[T,TT]
for i in range(1,n-1):
    x=k(a[i-1],x)
    for j in range(i+1,n):
        y=k(a[j],y)
    z=k(x,y)
    ans+=[z]
print(max(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
x=0
y=0
z=0
T=0
for i in a[1:]:
    T=k(i,T)

ans=[T]
for i in range(1,n-1):
    x=k(a[i-1],x)
    for j in range(i+1,n):
        y=k(a[j],y)
    z=k(x,y)
    ans+=[z]
print(max(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

if (n == 2):
   print(max(al_i[0],al_i[1]))
   sys.exit()

fg = [0] * n
bg = [0] * n

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1

for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n):
      g = fg[n-2]
   else:
      g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

fg = [0] * n
bg = [0] * n

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1

for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n):
      g = fg[n-2]
   else:
      g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)