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:
n = int(input())
a = list(map(int, input().split()))
ans = 1
i = 2
while(max(a) >= i):
    if len([x%i for x in a if x%i != 0]) > 1:
        i += 1
    else:
        ans = ans * i
        a = [int(x/i) if x%i == 0 else 1 for x in a]
print(ans)

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)-1:
                l_pop=l[:-1]
            else:
                l_pop=l[0:idx]+l[idx+1:]
            gcd=multi_gcd(l_pop)
            if (max_gcd<=gcd):
                max_gcd=gcd
               
        else : 
            pass
        
print(max_gcd)

Submission status: Wrong Answer

Solution code:
from functools import reduce
inf = 10**10
import sys
input = sys.stdin.readline


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def gcd_list(numbers):
    return reduce(gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
index = inf
if n == 2:
    print(max(a))
else:
    a.sort()
    if gcd(a[0],a[n-1]) == 1:
        print(max(gcd_list(a[1:n]),gcd_list(a[0:n-1])))
    else:
        ans = gcd(a[0],a[n-1])
        for i in range(1,n-1):
            if gcd(a[i]-a[0],a[n-1]-a[i]) <= ans:
                index = i
                ans = gcd(a[i]-a[0],a[n-1]-a[i])
        print(gcd_list(a[0:index]+a[index+1:n]))

Submission status: Wrong Answer

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

ls = [[fractions.gcd(A[i], A[j]) for j in range(N)] for i in range(N)]
result = 0

for row in ls:
    row = sorted(row, reverse=True)
    if row[1] > result:
        result = row[1]

print(result)

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())
array=[]
array=map(int,input().split())
array = list(array)
answer_array = []

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

def return_best_gcd(array):
    if(len(array)==2):
        return gcd(array[0],array[1])
    
    for drop in range(0,n):
        cp_array = copy.copy(array)
        del cp_array[drop]
        gcd_candidate = 1
        for index in range(0,(len(cp_array)-1)):
            val = gcd(cp_array[index],cp_array[index+1])
            if(val > gcd_candidate):
                gcd_candidate = val
        answer_array.append(gcd_candidate)
    return max(answer_array)


answer = return_best_gcd(array)
print(answer)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

g = gcd(A[0], A[1])
lmax = 1
num = 0
for i in range(2,N):
    cand = gcd(g, A[i])
    if cand < g:
        l = int(g / cand)
        g = cand
        if lmax < l:
            lmax = l
            num = A[i]
A = A[1:] + [A[0]]
g = gcd(A[0], A[1])
for i in range(2,N):
    cand = gcd(g, A[i])
    if cand < g:
        l = int(g / cand)
        g = cand
        if lmax < l:
            lmax = l
            num = A[i]
A = A[1:] + [A[0]]
g = gcd(A[0], A[1])
for i in range(2,N):
    cand = gcd(g, A[i])
    if cand < g:
        l = int(g / cand)
        g = cand
        if lmax < l:
            lmax = l
            num = A[i]
g = gcd(A[0], A[1])
flag = True
for i in range(2,N):
    if A[i] == num and flag:
        flag = False
    else:
        g = gcd(g, A[i])
print(g)

Submission status: Wrong Answer

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

N = int(input())
A = [int(i) for i in input().split()]
gc = gcd_list(A)
A.sort()
current = A[0]
for i in range(N):
    current = fractions.gcd(current,A[i])
    if(gc==current):
        break
b = A.pop(i)
gc1 = gcd_list(A)
A.append(b)
A.pop(i-1)
gc2 = gcd_list(A)
print(min(gc1,gc2))
# if(i<N-1):
#     gc2 = gcd_list(A[i+1:])
#     for j in range(i+1):
#         if(gc==fractions.gcd(gc2,A[j])):
#             break
#     A.pop(j)
#     print(gcd_list(A))

Submission status: Wrong Answer

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


n = int(input())
A = [int(x) for x in input().split()]
A.sort()
gcd_1 = [gcd(A[0],A[i]) for i in range(1,n)]

gcd_1.sort()

gcd_2 = A[1]

for i in range(2,n):
      gcd_2 = gcd(gcd_2,A[i])
#print(gcd_1)
if n == 2:
    print(gcd(A[0],A[1]))
else:
    print(max(gcd_1[1],gcd_2))

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)
  itemp2=ngcd(a[1:])
  #print(itemp, itemp2)
  print(max(itemp, itemp2))
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:
N=int(input())
A=[int(i) for i in input().split()]
def GCD(x,y):
	if x>y:
		a=x
		b=y
	else:
		a=y
		b=x
	while(True):
		c=a%b
		if c==0:
			return b
		else:
			a,b=b,c
 

if N==2:
	print(max(A))
else:
	B=[]
	a0=A[-1]
	for aa in A[1:]:
		B.append(GCD(aa,a0))
	gomikamo=B.index(min(B))+1
	g0=A[0]
	for i in range(0,N-1):
		g0=GCD(A[i],g0)
	del A[gomikamo]
	g1=A[0]
	for i in range(N-1):
		g1=GCD(A[i],g1)
	print(max(g0,g1))

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import numpy as np

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

A = 0

#maxi = np.argmax(a)
#mini = np.argmin(a)

a_del = np.delete(a, 0, 0)
List = list(a_del)
  
G = reduce(gcd,List)
#print(List)
A = max(A,G)

a_del = np.delete(a, 1, 0)
List = list(a_del)
  
G = reduce(gcd,List)
#print(G)
A = max(A,G)
print(A)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
min = min(a)
divisors = []
for i in range(1, int(min**0.5)+1):
    if min % i == 0:
        divisors.append(i)
        if i != min // i:
            divisors.append(min//i)
divisors.sort(reverse=True)
if n == 2:
    print(max(divisors))
else:
    judge = False
    for i in divisors:
        for j in range(n):
            if judge == True and a[j] % i !=0:
                judge = False
                break
            elif a[j] % i != 0:
                judge = True
        if judge == True:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions
from functools import reduce

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

def swap_gcd(arr, i, val):
    am = arr.copy()
    am[i] = val
    return reduce(fractions.gcd, am)

cm = np.prod(A)
gcds = [swap_gcd(A, i, cm) for i in range(N)]
print(max(gcds))

Submission status: Wrong Answer

Solution code:
def gcd(a):
    b = sorted(a)
    c = []
    t=0
    for i in range(len(b)):
        if b[i]%b[0]==0:
            t += 1
        else:
            c.append(b[i]%b[0])
    if len(c)==0:
        return b[0]
    else:
        return gcd(c)
n = int(input())
a = list(map(int,input().split()))
e = [0 for i in range(n)]
for i in range(n):
    e[i] = gcd(a[:i]+a[i+1:])
print(max(e))

Submission status: Wrong Answer

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

N = int(input())
integers = list(map(int, input().split()))
if len(integers) == 1:
    print(integers[0])
    sys.exit()
    
integers.sort(reverse = True)

gcds = [integers[0]]
for integer in integers[1:]:
    gcds.append(gcd(integer, gcds[-1]))
    
ans = [gcds[-2]]
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:
import fractions
from functools import reduce

n = int(input())
a_l =[int(i) for i in input().split()]
a_list=[a_l[n-1]]
a_list=a_list+a_l+[a_l[0]]

del_i = 0
for i in range(1,n+1):
    if fractions.gcd(a_list[i-1],a_list[i]) == 1 and fractions.gcd(a_list[i],a_list[i+1]) == 1:
        break
max_gcd=reduce(fractions.gcd, a_l)
del(a_l[i-1])
print(max(max_gcd,reduce(fractions.gcd, a_l)))

Submission status: Wrong Answer

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

def euclid(a, b):
    if a < b:
        tmp = a;
        a = b;
        b = tmp;

    r = a % b;
    while r != 0:
        a = b
        b = r
        r = a % b

    return b

if n == 2:
    print(max(a[0], a[1]))
    exit()
elif n == 3:
    print(max(euclid(a[0], a[1]), max(euclid(a[1], a[2]), euclid(a[0], a[2]))))
    exit()
else:
    t1 = euclid(a[0], a[1])
    t2 = euclid(a[1], a[2])
    t3 = euclid(a[0], a[2])

    l = [t1, t2, t3]
    l.sort(reverse=True)

    ans = l[0]
    flag = 0

    for i in range(3, n):
        if flag == 0 and a[i] % ans != 0:
            ans = l[1]
            flag = 1

        if flag == 1 and a[i] % ans != 0:
            ans = l[2]
            flag = 2

        if flag == 2 and a[i] % ans != 0:
            ans = euclid(a[i], ans)

print(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:
N = int(input())
A = list(map(int,input().split()))

a = sorted(A)
ans_list = []
def gcd(a,b):
    if a<b:
        a,b=b,a
    if b==0:
        return a
    c=a%b
    return gcd(b,c)

if len(A) == 2:
    ans_list.append(max(A))
try:
    for y in range(N):
        lis =list(A[:y:] + A[y+1:])
        fla = gcd(lis[0],lis[1])
        for x in range(N-1):
            ans_one = gcd(fla,lis[x])
            ans_list.append(ans_one)
except:
    pass
print(max(ans_list))

Submission status: Wrong Answer

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

def spaceinput():
    return list(map(int,input().split(" ")))



N=int(input())
a=sorted(spaceinput())



notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=rewrite[0]=best[0]=a[0]
for i in range(1,N):

    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([rewrite[i],gcd(a[i],best[i-1])])
    #print([notrewrite[i],rewrite[i]])



print(best[N-1])

Submission status: Wrong Answer

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

ls = [[fractions.gcd(A[i], A[j]) for j in range(N)] for i in range(N)]
ls = [sorted(row) for row in ls]
result = 0

for row in ls:
    row = sorted(row, reverse=True)
    if row[1] > result:
        result = row[1]

print(result)

Submission status: Wrong Answer

Solution code:
import collections
def gcd(a, b):
    if (b > a):
        a, b = b, a

    if (b == 0):
        return a
    return gcd(b, a%b) 
    
n = int(input())
a = [int (i) for i in input().split()]

gcd_list = []
for i in range(1, n):
    gcd_list.append(gcd(a[i], a[i-1]))

gcd_list.append(gcd(a[n-1],a[0]))
max_gcd = max(gcd_list)

c = collections.Counter(gcd_list)
most_common =  c.most_common()[0][0]

if c[max_gcd] >= n-2 and most_common < max_gcd:
    print(max_gcd)
else:
    print(most_common)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
answer = 0
i = lis[1]
while i >= 1:
  liss = []
  for j in range(n):
    liss.append(lis[j]%i)
  if liss.count(0) >= n-1:
    answer = i
    break
  i -= 1
print(answer)

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[min_index]
ans2 = a_list[0]
for j in range(N-1):
	ans2 = fractions.gcd(ans2, a_list[j])
print(max(ans1,ans2))

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

L = []

for i in range(N-1):
    gcd1 = 0
    A2 = A[:i] + A[i+1:]
    for j in range(N-2):
        gcd1 = gcd(A2[j], A2[j+1])
        A2[j+1] = gcd1
    L.append(gcd1)

print(max(L))

Submission status: Wrong Answer

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

def spaceinput():
    return list(map(int,input().split(" ")))



N=int(input())
a=sorted(spaceinput())



notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=rewrite[0]=best[0]=a[0]
for i in range(1,N):

    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([rewrite[i],gcd(a[i],best[i-1])])
    #print([notrewrite[i],rewrite[i]])

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from fractions import gcd
from functools import reduce
import sys
N = int(input())
A = list(set([int(i) for i in input().split()]))
 
def gcd_(*numbers):
    return reduce(gcd, numbers)

def prime(n):
    # 素数列挙
    # nまでの素数をリストで返す(nを含む)
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

num = gcd_(*A)
B = []
for x in A:
    B.append(x//num)
ls = prime(min(B))
for x in ls[::-1]:
    a = 0
    for y in B:
        if y%x != 0:
            a += 1
        if a >= 2:
            break
    if a == 1:
        print(num*x)
        sys.exit()
print(num)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# input
# 000

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

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

gcd_list = []

A.sort()

if len(A) == 2:
    if A[0] == A[1]:
        print(A[0])
        exit()
    elif A[0] > A[1]:
        print(A[0])
        exit()
    elif A[1] > A[0]:
        print(A[1])
        exit()


if A[1]%A[0] == 0:
    del A[0]
    A.insert(0, A[1])
else:
    del A[1]
    A.insert(1, A[0])


gcd_list = []
for a in A:
    for b in A:
        tmp = gcd(a, b)
        gcd_list.append(tmp)

    break

print(min(gcd_list))

Submission status: Wrong Answer

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


n = int(input())
A = [int(x) for x in input().split()]
A.sort()
gcd_1 = [gcd(A[0],A[i]) for i in range(1,n)]

gcd_1.sort()

gcd_2 = A[1]

for i in range(2,n):
      gcd_2 = gcd(gcd_2,A[i])
print(gcd_1)
if n == 2:
    print(gcd(A[0],A[1]))
else:
    print(max(gcd_1[1],gcd_2))

Submission status: Wrong Answer

Solution code:
def main():
  N=int(input())
  A=list(map(int, input().split()))
  
  for GCD in reversed(range(1,10**9)):
    error=0
    for i in range(0,N):
      if i%GCD==0:
        pass
      else:
        error+=1
        if error>=2:
          break
    if error<=1:
      break

  print(GCD)
    
main()

Submission status: Wrong Answer

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

A = sorted(A)

import fractions
dmax = []
maxa = max(A)
for i in range(N-1):
    dmax.append(fractions.gcd(maxa,A[i]))

dmax = sorted(dmax)
if len(dmax) == 1:
    print(dmax[0])
    exit()
if dmax[0] != dmax[1]:
    print(dmax[1])
else:
    print(dmax[0])

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 and v1 <= 10 ** 9:
        s1 = v1
    if count2 == 1 and v2 <= 10 ** 9:
        s2 = v2
    print(tmp * max(s1, s2))
else:
     print(tmp * min(v1, v2))

Submission status: Wrong Answer

Solution code:
def c():
    ans = 0
    N = long(raw_input())
    A = raw_input().split()
    for i in range(N):
        for j in range(i+1, N):
            C = long(A[i])
            D = long(A[j])
            #prlong "C:{}, D:{}".format(C,D)
            if C == D:
                g = C
            elif C > D:
                g = gcd(C, D)
            else:
                g = gcd(D, C)
            if g > ans:
                ans = g
    print ans

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

def main():
    c()
	
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def getNum(a, b):
    while(True):
        if a == b:
            return a
        a, b = max(a, b), min(a, b)
        a -= b

ans = max(AList[0], AList[1])
if N == 3:
    ans = max(getNum(AList[0], AList[1]), getNum(AList[1], AList[2]), getNum(AList[2], AList[0]))
elif N > 3:
    ansA = getNum(AList[0], AList[1])
    ansB = getNum(AList[1], AList[2])
    ansC = getNum(AList[2], AList[3])
    ansD, ansE = AList[0], AList[3]
    aFlag, bFlag, cFlag, dFlag, eFlag = True, True, True, True, True
    for num in AList:
        if num % ansA != 0:
            if not aFlag:
                ansA = 1
            aFlag = False
        if num % ansB != 0:
            if not bFlag:
                ansB = 1
            bFlag = False
        if num % ansC != 0:
            if not cFlag:
                ansC = 1
            cFlag = False
        if num % ansD != 0:
            if not dFlag:
                ansD = 1
            dFlag = False
        if num % ansE != 0:
            if not eFlag:
                ansE = 1
            eFlag = False
    ans = max(ansA, ansB, ansC, ansD, ansE)

print(ans)

Submission status: Wrong Answer

Solution code:
N  = int(input())
As = [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

# 最大公約数
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

devs = make_divisors(gcd(As[0],As[1]))
if N > 2:
    devs.extend(make_divisors(gcd(As[1],As[2])))
    devs.extend(make_divisors(gcd(As[2],As[0])))
devs = list(set(devs))
cnt = 1
for dev in sorted(devs)[::-1]:
    a = sum([a%dev==0 for a in As])
    if N - a == 0 or N - a == 1:
        print(dev)
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
i = 2
while(max(a) >= i):
    if len([x%i for x in a if x%i != 0]) > 1:
        i += 1
    else:
        ans = ans * i
        a = [int(x/i) if x%i == 0 else 1 for x in a]
        print(a)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd  # in math module python >= 3.5
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    calced = []
    for i in range(len(a)):
        if a[i] in calced:
            continue

        excepted = [a[j] for j in range(len(a)) if j != i]
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))

        calced.append(a[i])

    print(max(gcds))


main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
A = read_int()


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

def solve():
    gp = A[0]
    ga = 0
    g_l = []
    g_l.append(gp)
    for i in range(1,N):
        ga = gcd(max(gp, A[i]), min(gp, A[i]))
        gp = ga
        g_l.append(gp)
    gn = bisect.bisect_right(sorted(g_l), g_l[N - 1])
    # A[N - gn - 1] = A[N - gn - 2] if N - gn - 2 > 0 else A[N - gn]

    ans = 0
    gp = A[0]
    ga = 0
    for i in range(1, N):
        if i == N - gn - 1: continue
        ga = gcd(max(gp, A[i]), min(gp, A[i]))
        gp = ga
    ans =ga
    return ans


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
def find(inte):
    re = []
    for i in range(1,int(inte**0.5)+1):
        if inte%i==0:
            re.append(i)
            if i != inte/i:
                re.append(int(inte/i))
    return set(re)
flag =True
if n==2:
    intersection = find(A[0]) & find(A[1]) 
    print(max(intersection))
else:
    a1 = find(A[0])
    a2 = find(A[1])
    a3 = find(A[2])
    max1 = max(a1&a2)
    max2 = max(a1&a3)
    max3 = max(a2&a3)
    ans = max(max1,max2,max3)
    for a in A[3:]:
        if a%ans != 0:
            print(1)
            flag = False
            break
    if flag:
        print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:01:24 2019
ABC125C
@author: maezawa
"""

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

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

a0 = a[0]
mingcd = a0
min0 = 0
for i in range(1,n):
    gcdi = gcd(a0, a[i])
    if gcdi < mingcd:
        mingcd = gcdi
        min0 = i
 
a1 = a[-1]
mingcd1 = a1
min1 = n-1
for i in range(n-1):
    gcdi = gcd(a1, a[i])
    if gcdi < mingcd1:
        mingcd1 = gcdi
        min1 = i

nend = n-1
if mingcd < mingcd1:
    a.pop(min0)
elif mingcd > mingcd1:
    a.pop(min1)
else:
    nend = n


maxgcd = 1
a0 = a[0]
for i in range(1,nend):
    gcdi = gcd(a0,a[i])
    if gcdi > maxgcd:
        maxgcd = gcdi
print(maxgcd)

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()))
a.sort(reverse=True)
crt_gcd=a[0]
cng=-1
for i, ai in enumerate(a):
  gcdi = gcd(crt_gcd, ai)
  if gcdi<crt_gcd:
    cng=i-1
    crt_gcd=gcdi
if len(a)==2:
  crt_gcd=a[0]
elif cng==0:
  crt_gcd=a[min(len(a)-1, 2)]
else:
  crt_gcd=a[0]

for i, ai in enumerate(a):
  if i!=cng and i!=cng+1:
    gcdi = gcd(crt_gcd, ai)
    if gcdi<crt_gcd:
      crt_gcd=gcdi

print(max(gcd(crt_gcd, a[cng]), gcd(crt_gcd, a[cng+1]), gcd(a[cng], a[cng+1])))

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin
import numpy as np

n = int(stdin.readline().rstrip())
nums = np.sort(np.array(list(map(lambda x: int(x), stdin.readline().rstrip().split()))))

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

if len(nums) == 2:
    print(max(nums))
else:
    print(max(gcd(nums[-1],nums[-2]), gcd(nums[-2],nums[-3]), gcd(nums[-1],nums[-3])))

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
A.sort()
ans = 1000000000
Al = []
if len(A) >= 3:
    for lop in range(2,len(A),3):
        A1 = fractions.gcd(A[lop-2],A[lop-1])
        A2 = fractions.gcd(A[lop-2],A[lop])
        A3 = fractions.gcd(A[lop-1],A[lop])
        Al.append(max(A1,A2,A3))
    print(min(Al))
else:
    print(max(A))

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import numpy as np

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

A = 0

#maxi = np.argmax(a)
#mini = np.argmin(a)

a_del = np.delete(a, 0, 0)
List = list(a_del)
  
G = reduce(gcd,List)
print(List)
A = max(A,G)

a_del = np.delete(a, 1, 0)
List = list(a_del)
  
G = reduce(gcd,List)
#print(G)
A = max(A,G)
print(A)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
arr=list(map(int,input().split()))
if n==2:
  print(gcd(arr[0],arr[1]))
elif n==3:
  print(max(gcd(arr[0],arr[1]),gcd(arr[1],arr[2]),gcd(arr[2],arr[0])))
else:
  ans1=[]
  for i in range(3,n):
    ans1.append(gcd(gcd(arr[0],arr[1]),arr[i]))
  ans1=sorted(ans1)
  ans2=[]
  for i in range(3,n):
    ans2.append(gcd(gcd(arr[1],arr[2]),arr[i]))
  ans2=sorted(ans2)
  ans3=[]
  for i in range(3,n):
    ans3.append(gcd(gcd(arr[2],arr[0]),arr[i]))
  ans3=sorted(ans3)
  if n==4:
    finans1=ans1[0]
    finans2=ans2[0]
    finans3=ans3[0]
  else:
    finans1=ans1[1]
    finans2=ans2[1]
    finans3=ans3[1]
  finalans=max(finans1,finans2,finans3)
  print(finalans)

Submission status: Wrong Answer

Solution code:
from copy import copy

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

N = ii()
A = li()

def gcd_array(a):
    if len(a) == 1:
        return a[0]
    min_a = min(a)
    a = list(filter(lambda i: i != min_a, a))
    if min_a == 0:
        return min(a)
    else:
        return gcd_array([i % min_a for i in a] + [min_a])

RA= []
for i in range(N):
    a = copy(A)
    a.pop(i)
    RA.append(gcd_array(a))

print(max(RA))

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[j])
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import copy
import math
from functools import reduce

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

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

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n = int(input())
a = list(map(int, input().split()))
a.sort()
rtn = gcd_list(a)
if rtn == 1:
    for x in a:
        if is_prime(x):
            a.remove(x)
            break
    rtn = gcd_list(a)
    print(int(rtn))
else:
    a_2 = [x / rtn for x in a]
    for x in a_2:
        if is_prime(x):
            a_2.remove(x)
            break
    rtn_2 = gcd_list(a_2)
    print(int(rtn * rtn_2))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
    
n = ni()
a = list(li())

a.sort()

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

print(sorted(gcds)[1] if n > 2 else max(a[0], a[1]))

Submission status: Wrong Answer

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

N=int(input())
A=[int(s)for s in input().split()]
A=sorted(A)
gcd=A[0]
gcd2=A[1]
for i in range(2,N):
  gcd=gcdf(A[i],gcd)
  gcd2=gcdf(A[i],gcd2)
print(max((gcd,gcd2)))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
answer = 0
i = lis[1]
while True:
  liss = []
  for j in range(n):
    liss.append(lis[j]%i)
  if liss.count(0) >= n-1:
    answer = i
    break
  i -= 1
print(answer)