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
# gcd
import fractions
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
from functools import reduce


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


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


#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
old_gcd = gcd_list(A)
for i in range(N):
    A[i] = A[i] // old_gcd
left = -1
right = N
while (right - left > 1):
    mid = left + (right - left) // 2
    # print(mid)
    if gcd_list(A[mid:N]) == 1:
        left = mid
    else:
        right = mid
A.pop(left)
# print(A)
print(old_gcd * gcd_list(A))
# print(A)
#
# num = N
# ans = []
# while num != 2:
#     ans = []
#     if num % 2 == 0:
#         num = -(-num // 2)
#         for i in range(num):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#     else:
#         num = -(-num // 2)
#         for i in range(num - 1):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#             ans.append(A[-1])
#     if ans.count(1) >= 2:
#         print(old_gcd)
#         break
# else:
#     print(max(ans))

Submission status: Wrong Answer

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

### 一旦最大値を求める
maxA = max(A)
print(maxA)

# 各変数ごとに、最大値からの差分を求める
delta = [maxA - a for a in A]
print(delta)

if delta.count(0) == len(A):
    print(maxA)
else:
    # 差分の最大値を求める。これが２変数間の最大公約数の候補
    deltaMax = max(delta)
    #print(deltaMax)

    # 最大公約数となり得るか、余りを求めてみる。２変数以上でゼロならOK
    aDeltaMax = [a % deltaMax for a in A if deltaMax > 0]
    #print(aDeltaMax)
    
    if (aDeltaMax.count(0) >= 2):
        print(deltaMax) 
    else:
        # 余りのうち、２つ以上同値があれば、それもOK
        for ad in aDeltaMax:
            if aDeltaMax.count(ad) >= 2:
                print(ad)
                break

Submission status: Wrong Answer

Solution code:
import copy

tmp = 0
Max = 1

N = int(input())

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

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

if N != 2:

    for i in range(N):
    
        tmp_list = copy.copy(A_list)
        del tmp_list[i] #i番目が存在しないリストを作成
        #print(tmp_list)
        
        tmp = operation(tmp_list[0],tmp_list[1])#最初の2つの最大公約数
    
        for k in range(N-2):
            tmp = operation(tmp,tmp_list[k])
    
        if tmp > Max:
            Max = tmp

    print(Max)
    
else:
    print(max(A_list))

Submission status: Wrong Answer

Solution code:
import fractions 

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


if n == 2:
  print(fractions.gcd(a[0],a[1]))
  exit()
temp = a[0]
  
for i in range(1,n-1):
  temp = max(fractions.gcd(temp,a[i]),fractions.gcd(temp,a[i+1]))

print(temp)

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
n_gcd = a[0]
point_a = 0
point_b = 0
for i in range(1, n):
    num = fractions.gcd(n_gcd, a[i])
    if num < n_gcd:
        point_a, point_b = i-1, i
        n_gcd = num
a_b = copy.copy(a)
a.pop(point_a)
a_b.pop(point_b)
n_gcd_a = a[0]
n_gcd_b = a_b[0]
if len(a) == 1:
    print(max(a[0], a_b[0]))
    exit()
for i in range(1, n-1):
    n_gcd_a = fractions.gcd(n_gcd_a, a[i])
for i in range(1, n-1):
    n_gcd_b = fractions.gcd(n_gcd_b, a_b[i])
print(max(n_gcd_a, n_gcd_b))

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

n = int(input())
a = [ int(x) for x in input().split() ]
_gcd = reduce(gcd, a)

b = [ int(x)//_gcd for x in a ]

t = b[0]
cnt = 0
for i in b[1:]:
    if (gcd(t, i) == 1):
        if cnt == 0:
            cnt += 1
        else:
            t = 1
    else:
        t = gcd(t, i)

ans = (_gcd * t)

t = b[1]
cnt = 0

for i in [b[0]] + b[2:]:
    if (gcd(t, i) == 1):
        if cnt == 0:
            cnt += 1
        else:
            t = 1
    else:
        t = gcd(t, i)

ans = max(ans, (_gcd * t))

print(ans)

Submission status: Wrong Answer

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

def getdiff(A, a_min):
  ret = []
  for a in A:
    d = a % a_min
    if d != 0:
      ret.append(d)
  return(ret)

l = len(A)
while 2 < l:
  a_min = min(A)
  A.remove(a_min)
  a_ret = min(A)
  A = getdiff(A, a_min)
  l = len(A)

if l == 0:
  print(a_ret)
else:
  print(max(A))

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
s=[]
def gcd(p,q):
  while p%q:
    t=p%q
    p=q
    q=t
  return q
for i in range(n-1):
  for j in range(i+1,n):
    ma=max(a[i],a[j])
    mi=min(a[i],a[j])
    s.append(gcd(ma,mi))
for c in sorted(set(s))[::-1]:
  if s.count(c)==n*(n-1)/2-(n-1)or s.count(c)==len(s):
    print(c)
    exit()

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
list_a=list(map(int, input().split()))
def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a%b)
if n == 2:
	print(max(list_a))
else:
	p = []
	for i in range(n-1):
		p.append(gcd(list_a[i], list_a[i+1]))
	p.append(gcd(list_a[0], list_a[n-1]))
	p_arr = np.array(p)
	if len(p_arr[np.where(p_arr == min(p_arr))]) <= 2:
		p.remove(min(p))
		p.remove(min(p))
		print(min(p))
	else:
		print(min(p))

Submission status: Wrong Answer

Solution code:
import numpy as np

def gcd_(a, b):
    a_ = max(a, b)
    b_ = min(a, b)

    while True:
        if a_ % b_ == 0:
            return b_
        a_, b_ = b_, a_ % b_

_ = input()
a = np.array([int(x) for x in input().split(" ")])

if len(a) == 2:
    print(gcd_(*a))
    exit()

list = [gcd_(a[2], a[1]), gcd_(a[0], a[2]), gcd_(a[0], a[1])]
gcd = np.max(list)
bad_num = a[np.argmax(list)]

for i in range(3, len(a)):
    if a[i] % gcd == 0:
        continue
    else:
        newgcd = gcd_(a[i], gcd)
        oldgcd = gcd_(bad_num, gcd)

        if newgcd > oldgcd:
            gcd = newgcd
        else:
            gcd = oldgcd
            bad_num = a[i]


print(gcd)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
num_list = []
divisor_list = []
for i in range(N):
    div_list = make_divisors(A[i])
    for j in range(len(div_list)):
        if div_list[j] in divisor_list:
            num_list[divisor_list.index(div_list[j])] += 1
        else :
            divisor_list.append(div_list[j])
            num_list.append(1)

M = len(num_list)
for i in range(len(num_list)):
    if num_list[M-i-1] == N or num_list[M-i-1] == (N-1):
        print(divisor_list[M-i-1])
        break

Submission status: Wrong Answer

Solution code:
from collections import deque

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


import fractions
from functools import reduce

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


ans=0
GCD_target=gcd_list(A)
#print("GCD_target = {}".format(GCD_target))

for i in range(N):
   #copied_A = A[:]
   remove=A.popleft()
   GCD_current=1 #gcd_list(list(A))
   A.append(remove)
   #print(GCD_current)
   ans=max(ans,GCD_current)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
Alist = list(map(int, input().split()))
def gcd_list(numbers):
  return reduce(gcd, numbers)
if len(Alist) == 2:
    print(max(Alist))
else:
    gcdlist=[gcd_list(Alist[i:i+2]) for i in range(N-1)]
    ind = gcdlist.index(min(gcdlist))
    print(max([gcd_list(Alist[:ind]+Alist[ind+1:]), gcd_list(Alist[:ind+1]+Alist[ind+2:])]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = 1
k = []
g = []
l = []
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

x = gcd(A[0], A[1])
k.append(x)
for i in range(2, N):
    x = gcd(x, A[i])
    k.append(x)
cost = 0
for i in range(N-2):
    if k[i] == k[i+1]:
        if cost == 0:
            g.append([i, i+1])
        cost += 1
    else:
        if len(g) < 1:
            continue
        l.append([cost, g[len(g)-1]])
        cost = 0
if len(g) <= 0:
    print(x)
    exit()

l.append([cost, g[len(g)-1]])

index1 = l[len(l)-1][1][0]
index2 = l[len(l)-1][1][1]
temp = A[index1]

for i in range(N):
    if A[index1] != A[i]:
        B = A[i]
        break

A[index1] = B

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

A[index1] = temp

for i in range(N):
    if A[index2] != A[i]:
        B = A[i]
        break

A[index2] = B

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

print(max(x, y))

Submission status: Wrong Answer

Solution code:
import fractions

N=int(input())
a_list = [int(i) for i in input().split()]
a_list.sort()
b_list = a_list[:]
del b_list[-1]
ans1 = b_list[0]
for i in range(N-1):
	ans1 = fractions.gcd(ans1, b_list[i])

max_number = a_list[-1]
min_number = a_list[-1]
min_index = 0
for i in range(N-1):
	gcd = fractions.gcd(max_number,a_list[i])
	if gcd < min_number:
		min_index = i
		min_number = gcd

del a_list[i]
ans2 = a_list[0]
for j in range(N-1):
	ans2 = fractions.gcd(ans2, a_list[i])
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import fractions
import numpy as np

N = int(input())
A = np.array(sorted([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)

    return divisors

divisors=make_divisors(A[0])
divisors_1=make_divisors(A[1]) 
divisors.extend(divisors_1)

def gcd(l):
    ans = l[0]
    for j in range(1, N-1):
        ans = fractions.gcd(ans, l[j])
    return ans


for i in sorted(list(set(divisors))):
    if(np.sum(np.where(A%i != 0)[0])<=1):
        res = i


print(res)

Submission status: Wrong Answer

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

def gcd(t1,t2):
    while t2:
        t1,t2=t2,t1%t2
    return t1

if n==2:
    print(max(a))
    exit()

a.sort()
ans=[gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])]
tmp1=max(ans)
tmp2=tmp1
for i in range(2,n):
    tmp1=gcd(tmp1,a[i])
    if tmp1!=tmp2:
        ans+=[tmp1]
        tmp2=tmp1
ans.sort()
if len(ans)>1:
    print(ans[2])
else:
    print(ans[0])

Submission status: Wrong Answer

Solution code:
def gcd(p,q):
  while q!=0:
    p,q=q,p%q
  return p

n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
cnt1=0
d=a[0]
e=a[0]

if n==2:
  print(a[0])
elif gcd(a[0],a[1])==1:
  b=a[0]
  c=a[1]
  for i in range(n-2):
    if gcd(b,a[i+2])==1:
      b=1
      break
    else:
      b=gcd(b,a[i+2])
  for i in range(n-2):
    if gcd(c,a[i+2])==1:
      c=1
      break
    else:
      c=gcd(c,a[i+2])
  print(max(b,c))
else:
  for i in range(n-2):
    if gcd(d,a[i+1])==1 and cnt1==0:
      cnt1=1
      continue
    elif gcd(d,a[i+1])==1 and cnt1==1:
      d=1
      break
    else:
      if gcd(d,a[n-1])==1:
        d=1
      else:
        d=gcd(d,a[i+1])
  print(d)

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
A = sorted(list(map(int,input().split())),key=lambda x:abs(x))

ans = []
for i in range(N - 1):
  ans.append(fractions.gcd(A[i],A[i + 1]))
  if i + 2 < N:
    ans.append(fractions.gcd(A[i],A[i + 2]))

ans.sort()
print(max(A) if N == 2 else (ans[-1] if N == 3 else ans[3]))
#print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# gcd
import fractions
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
from functools import reduce


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


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


#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
old_gcd = gcd_list(A)
for i in range(N):
    A[i] = A[i] // old_gcd
left = -1
right = N
while (right - left > 1):
    mid = left + (right - left) // 2
    # print(mid)
    if gcd_list(A[mid:N]) != 1:
        right = mid
    else:
        left = mid
A.pop(left)
# print(A)
print(old_gcd * gcd_list(A))
# print(A)
#
# num = N
# ans = []
# while num != 2:
#     ans = []
#     if num % 2 == 0:
#         num = -(-num // 2)
#         for i in range(num):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#     else:
#         num = -(-num // 2)
#         for i in range(num - 1):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#             ans.append(A[-1])
#     if ans.count(1) >= 2:
#         print(old_gcd)
#         break
# else:
#     print(max(ans))

Submission status: Wrong Answer

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

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

if sum(A) % 2 != 0:
    print(gcd(max(A), min(A)))

else:
    A.remove(min(A))
    print(gcd(max(A), min(A)))

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 1
odd = 0
even = 0
for a in As:
    if a%2 == 0:
        even += 1
    else:
        odd += 1
if even >= 2 and odd >= 2:
    print(1)
else:
    
    for i in range(N):
        flag = True
        if i == 0:
            a = As[1]
        else:
            a = As[0]
        for j in range(N):
            if j != i:
                a = fractions.gcd(a, As[j])
                if a <= ans:
                    flag = False
                    break
        if flag:  
            ans = a
    print(ans)

Submission status: Wrong Answer

Solution code:
import math


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def dev(A, n):
    B = [int(a / n) for a in A if a % n == 0]
    return B, len(A) - len(B)




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

    A.sort()
    _max = A[1]**0.5 + 1
    prime_list = get_sieve_of_eratosthenes(math.floor(_max))
    yaku = 1
    i = -1
    while True:
        i += 1
        if len(prime_list) < i +1 :
            break
        if len(A) == 0:
            break
        B, d = dev(A, prime_list[i])
        # print(A, prime_list[i], B, d)
        if d > 1:
            continue
        if N - len(B) > 1:
            continue
        yaku *= prime_list[i]
        A = B
        # print(yaku, prime_list[i])
        i -= 1
    print(yaku)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()

res = []

if N == 1:
    print(A[0])
else:
    if len(A) >= 3:
        gcd_num = max(fractions.gcd(A[0], A[1]), fractions.gcd(A[0], A[2]), fractions.gcd(A[1], A[2]))
    else:
        gcd_num = max(A[0], A[1])
        
    print(gcd_num)

Submission status: Wrong Answer

Solution code:
_=input()
l=list(map(int, input().split()))

def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y   
    return x 
def multi_gcd(l):
    if len(l)==1:
        return l[0]
    else:
        gcd=find_gcd(l[0],l[1]) 
        for j in range(2,len(l)): 
            gcd=find_gcd(gcd,l[j])
        return gcd

gcd_max=0
key=[-1,-1]
if len(l)==2:
    max_gcd=(max(l[0],l[1]))
elif len(l)==3:
    max_gcd=max(find_gcd(l[0],l[1]),find_gcd(l[0],l[2]),find_gcd(l[2],l[1]))
else:
    l_left,l_right=l[:len(l)//2],l[len(l)//2:]
    a,b=multi_gcd(l_left),multi_gcd(l_right)
    max_gcd=multi_gcd(l)
    l_mod_flag_a=[int(i%a>0) for i in l ]
    l_mod_flag_b=[int(i%b>0) for i in l ]
    if sum(l_mod_flag_a)==1:
        try : key[0]=l_mod_flag_a.index(1)
        except : pass
    if sum(l_mod_flag_b)==1:
        try: key[1]=l_mod_flag_b.index(1)
        except : pass
    for i in range(2):
        if key[i]!=-1:
            idx=key[i]
            if idx==len(l):
                l_pop=l[:-1]
            else:
                l_pop=l[0:idx]+l[idx+1:]
            gcd=find_gcd(l_pop[0],l_pop[1]) 
            for j in range(2,len(l)): 
                gcd=find_gcd(gcd,l[j])
            if (max_gcd<=gcd):
                max_gcd=gcd
        else : 
            pass
        
print(max_gcd)

Submission status: Wrong Answer

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

from fractions import gcd

b = [0] * n

if n == 2:
    print(gcd(a[0], a[1]))
else:
    for i in range(n):
        for j in range(i+1, n):
            for k in range(n):
                if k != i and k != j:
                    gcd_num = gcd(a[i], a[j])
                    if b[k] == 0:
                        b[k] = gcd_num
                    else:
                        b[k] = gcd(gcd_num, b[k])

    b.sort()
    print(b[-1])

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
A = list(set(A))
ans = 0
A = sorted(A)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
ans = 0
ans_ = 0
if len(A) == 1:
  print(max(A))
elif len(A) == 2:
  print(max(A))
elif len(A) == 3:
  tmp = [A[0],A[1],A[len(A)-1]]
else:
  tmp = [A[0],A[1],A[len(A)-2],A[len(A)-1]]
  for i in range(len(tmp)):
    tmp_ = tmp[:]
    tmp_.pop(i)
    ans_ = gcd_list(tmp_)
    if ans < ans_:
      ans = ans_
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
#A = np.array(list(map(lambda x: int(x),input().split())))
A = list(map(lambda x: int(x),input().split()))
A.sort()
#print(A)
ans = -1
if N==2:
    ans = max(A)
else:
    for j in range(len(A)):
        A_dropped = A[:j]+A[j+1:]
        B = np.array([A_dropped[(i+1)] - A_dropped[i] for i in range(len(A_dropped)-1)])
        b = min(B)
        #print(b)
        if b==0:
            ans = A_dropped[0]
        else:
            C = B%b
            if sum(C)==0:
                ans = max(ans,b)

print(ans)

Submission status: Wrong Answer

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

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(len(li)-3):
            temp=gcd(temp, li[i+2])
    return temp

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

t=a[0]
t2=a[1]
out=0
f=1
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    #print(t, a[i],out, min)
"""
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t2, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    print(t2, a[i],out, min)


print(out)
"""

"""
  if not (a[i]%t==0 or t %a[i]==0):
    if f:
      out=i
      f=0
    elif not f:
      out=0
"""
if not len(a)==2:
  temp=a[0:out]
  temp.extend(a[out+1:])
  #print(temp)
  itemp=ngcd(temp)
  print(itemp)
else:
  print(max(a[0], a[1]))


"""
max=0
for i in range(len(a)):
    temp=a[0:i]
    temp.extend(a[i+1:])
    itemp=ngcd(temp)
    if max < itemp:
        max=itemp

print(max)
"""

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

gcd_right = []
gcd_right.append(A[N-1])
for i in range(N-1):
    gcd_right.insert(0,fractions.gcd(gcd_right[0],A[N-2-i]))

Submission status: Wrong Answer

Solution code:
import fractions

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

a.sort()

if n == 2:
    print(a[1])
elif n == 3:
    gcd1 = fractions.gcd(a[0],a[1])
    gcd2 = fractions.gcd(a[1],a[2])
    gcd3 = fractions.gcd(a[0],a[2])
    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

else:
    gcd1 = fractions.gcd(a[0],a[1])
    gcd2 = fractions.gcd(a[1],a[2])
    gcd3 = fractions.gcd(a[0],a[2])

    for i in range(3,n):
        if fractions.gcd(gcd1, a[i]) < gcd1:
            gcd1 = fractions.gcd(gcd1, a[i])

    for i in range(3,n):
        if fractions.gcd(gcd2, a[i]) < gcd2:
            gcd2 = fractions.gcd(gcd2, a[i])

    for i in range(3,n):
        if fractions.gcd(gcd3, a[i]) < gcd3:
            gcd3 = fractions.gcd(gcd3, a[i])

    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

def list_primes(A):
    pn=[2]
    for L in range(3,A):
        chk=True
        for L2 in pn:
            if L%L2 == 0:chk=False
        if chk==True:pn.append(L)
    return pn

prime_list = list_primes(max(As))
max_prime = 0
max_prime_n = 0
for n,i in enumerate(prime_list):
    max_prime_now = max(list(map( lambda x: i if x % i == 0 else 0, As)))
    if max_prime_now > max_prime:
        max_prime = max_prime_now
        max_prime_n = n
As_np = np.array(As)
As_np[As_np%max_prime==0]=max(As_np)

sigma = 1
len_As = len(As_np)
for i in reversed(range(2,max(As_np)+1)):
    if (As_np % i).sum()==0:
        As_np = As_np/i
        sigma *= i

print(sigma)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
n = input()
lists = list(map(int, input().split()))
gcd1 = functools.reduce(fractions.gcd, lists)
i=1
y=1
judge = "true"
min = min(lists)
max = max(lists)
#print(limit)
while i < min:
  for index,list in enumerate(lists):
    if (list % i) != 0:
      lists[index] = max
      judge = "false"
      break
  if judge == "false":
    break
  i += 1
#print(lists)
gcd2 = functools.reduce(fractions.gcd, lists)
if gcd1 >= gcd2:
  print(gcd1)
else:
  print(gcd2)

Submission status: Wrong Answer

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

N = int(input())
integers = list(map(int, input().split()))
integers.sort()

gcds = [integers[0]]
for integer in integers[1:]:
    gcds.append(gcd(integer, gcds[-1]))
    
ans = [gcds[-2], gcds[-1]]
for i in range(len(gcds) - 2):
    ans.append(gcd(gcds[i], integers[i + 2]))

temp = integers[1]
for integer in integers[2:]:
    temp = gcd(temp, integer)
ans.append(temp)
print(max(ans))

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
s=[]
def gcd(p,q):
  while p%q:
    t=p%q
    p=q
    q=t
  return q
for i in range(n-1):
  for j in range(i+1,n):
    ma=max(a[i],a[j])
    mi=min(a[i],a[j])
    s.append(gcd(ma,mi))
for c in sorted(set(s))[::-1]:
  if s.count(c)==n*(n-1)/2-(n-1):
    print(c)
    exit()

Submission status: Wrong Answer

Solution code:
from functools import*;from fractions import*
n,*a=map(int,open(0).read().split())
print(max(reduce(gcd,a[n//4:]),reduce(gcd,a[:n//4]+a[n//2:]),reduce(gcd,a[:n//2]+a[3*n//4:]),reduce(gcd,a[:3*n//4])))

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 1
odd = 0
even = 0
for a in As:
    if a%2 == 0:
        even += 1
    else:
        odd += 1
if even >= 2 or odd >= 2:
    print(1)
else:
    
    for i in range(N):
        flag = True
        if i == 0:
            a = As[1]
        else:
            a = As[0]
        for j in range(N):
            if j != i:
                a = fractions.gcd(a, As[j])
                if a <= ans:
                    flag = False
                    break
        if flag:  
            ans = a
    print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n == 2:
    print(max(*as_))
else:
    set_ = set()
    gcd_all = as_.pop()
    for a in as_:
        set_ = set(gcd(s, a) for s in set_)
        set_.add(gcd_all)
        gcd_all = gcd(gcd_all, a)

    print(max(set_))

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = [int(x) for x in input().split()]

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

if len(a_list) == 2:
    print(max(a_list))
if len(a_list) == 3:
    tmp_1 = func(a_list[0], a_list[1])
    tmp_2 = func(a_list[1], a_list[2])
    tmp_3 = func(a_list[0], a_list[2])
    print(max(tmp_1,tmp_2,tmp_3))
if len(a_list) >= 4:
    tmp_1 = func(a_list[0], a_list[1])
    tmp_2 = func(a_list[2], a_list[3])

#     print(tmp_1,tmp_2)
    def check_all(tmp):
        miss_cnt = 0
        for a in a_list:
            if a % tmp != 0:
                miss_cnt += 1
            if miss_cnt >= 2:
                return 1
        return tmp
    
    ca_1 = check_all(tmp_1)
    ca_2 = check_all(tmp_2)
#     print(ca_1,ca_2)
    
    print(max(ca_1,ca_2))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import random
import copy

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

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

if n < 200:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in range(200):
    t = gcd(random.sample(a, 50))
    if ans < t:
      ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
s=1
  
for i in A:
  s=s*i
if s<=10**9:
  answer=1
  for i in range(0,N):
    change=A[i]
    A[i]=s
    g=A[0]
    for j in range(0,N):
      if g>=A[j]:
        large=g
        small=A[j]
      else:
        large=A[j]
        small=g
      while (large%small!=0):
        r=large%small
        large=small
        small=r
      g=small
    if answer<g:
      answer=g
    A[i]=change
  print(answer)
else:
  answer=1
  for i in range(0,N):
    g=A[0]
    for j in range(0,N):
      if g>=A[j]:
        large=g
        small=A[j]
      else:
        large=A[j]
        small=g
      while (large%small!=0):
        r=large%small
        large=small
        small=r
      g=small
    if answer<g:
      answer=g
  for i in range(0,N):
    A[i]=A[i]/answer
  g=A[0]
  for j in range(0,N):
    if g>=A[j]:
      large=g
      small=A[j]
    else:
      large=A[j]
      small=g
    while (large%small!=0):
      r=large%small
      large=small
      small=r
    if small==1:
      if answer<=10**9:
        A[j]=answer*g
      break
    g=small
  g=A[0]
  for j in range(0,N):
    if g>=A[j]:
      large=g
      small=A[j]
    else:
      large=A[j]
      small=g
    while (large%small!=0):
      r=large%small
      large=small
      small=r
    if small==1:
      A[j]=answer*g
      break
    g=small
  print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = [int(i) for i in input().split()] 
#print(n,a)
maxa=max(a)
cnt=0
flag=0
for i in range(n):
  if a[i] < maxa:
    cnt+=1
  if cnt>=2:
    flag=1
    break 
    
mina=min(a)
gcda=0
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

for i in range(n):
  if a[i] < maxa:
    val=gcd(maxa,a[i])
    if val > gcda:
      gcda=val
      
print(gcda if flag==1 else maxa)

Submission status: Wrong Answer

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

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
    
v1 = A[0]
count1 = 0
for i in range(N):
    tmp1 = v1
    v1 = gcd(v1, A[i])
    if  v1 == 1:
        count1 += 1
        if count1 == 1:
            v1 = tmp1
        
        
v2 = A[1]
count2 = 0
for i in range(N):
    tmp2 = v2
    v2 = gcd(v2, A[i])
    if v2 == 1:
        count2 += 1
        if count2 == 1: 
            v2 = tmp2

if N != 2:
    s1 = 1
    s2 = 1
    if count1 == 1:
        s1 = v1
    if count2 == 1:
        s2 = v2
    print(tmp * max(s1, s2))
else:
     print(tmp * min(v1, v2))

Submission status: Wrong Answer

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

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

r=[]
l=[]
resr = ai[0]
resl = ai[n-1]
r.append(ai[0])
l.append(ai[n-1])
for i in range(1,n):
	r.append(gcd(resr,ai[i]))
	l.append(gcd(resl,ai[n-1-i]))

#print(r)
#print(l)

resmax = 0
for i in range(n):
	if i == 0:
		res = l[n-1-1]
	elif i == n-1:
		res = r[n-1-1]
	else:
		res = gcd(r[i-1], l[n-1-i-1])
	#print(res)
	if res > resmax:
		resmax = res

    
print(resmax)

Submission status: Wrong Answer

Solution code:
import copy

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

def gcd_list(A,N):
    for i in range(N-1):
        if i == 0:
            tmpgcd = gcd(A[i],A[i+1])
        else:
            tmpgcd = gcd(tmpgcd,A[i+1])
    return tmpgcd

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

MAXNUM = max(A)
MGCD = 0
COPYA = copy.deepcopy(A)

for i in range(N):
    if i > 0:
        A[i-1] = COPYA[i-1]
    for n in range(1,MAXNUM):
        A[i] = n
        tmp = gcd_list(A,N)
        if tmp > MGCD:
            MGCD = tmp

print(MGCD)