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 fractions
from functools import reduce

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

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

if N == 2:
  ans = max(A_list)
else:
  A_gcd = gcd_list(A_list)
  A_list = list(map(lambda x: x/A_gcd, A_list))
  remove_index = 0
  A_list.sort()
  for i in range(N-1):
    a = fractions.gcd(A_list[i], A_list[i+1])
    if a==1 and i != 0:
      remove_index += i+1
      break;
    elif i == 0 and a==1:
      b = fractions.gcd(A_list[1], A_list[2])
      if b == 1:
        remove_index += 1
      else:
        remove_index += 0
      break;
  A_list.pop(remove_index)
  ans = gcd_list(A_list) * A_gcd
print(int(ans))

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:
from functools import reduce
import numpy as np

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

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

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

while True:
    count+=1
    for i in range(N):
        if A[i]%count == 0:
            pass
        else:
            A[i] = A[i-1]
            break
    else:
        continue
    break

print(gcd_list(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
import sys
def gcd(a,b): 
    if(b==0): 
        return a 
    else: 
        return gcd(b,a%b) 
flag = True
if n==2:
    print(A[1])
else:
    a1 = gcd(A[0],A[1])
    a2 = gcd(A[0],A[2])
    a3 = gcd(A[1],A[2])
    ans = max(a1,a2,a3)
    for a in A:
        if a%ans != 0:
            print(1)
            flag = False
            break
    if flag:
        print(ans)

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([notrewrite[i],rewrite[i],gcd(a[i],best[i-1])])

print(best[N-1])

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
gcdL = [0] * N
gcdR = [0] * N

gcdL[0] = A[0]
gcdR[-1] = A[-1]

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

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

ans = gcdR[1]
for i in range(1, N-1):
    tmp = gcd(gcdL[i-1], gcdR[i+1])
    ans = max(tmp, ans)
ans = max(ans, gcdL[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

max_gcd = functools.reduce(fractions.gcd, A)

for i in range(N):
	if A[i] % 2 == 1:
		tmp = A.copy()
		tmp.pop(i)
		gcd = functools.reduce(fractions.gcd, tmp)
		if max_gcd < gcd:
			max_gcd = gcd

print(max_gcd)

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:
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):
        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:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

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

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

  def gcd(m, n):
    while n:
      m, n = n, m%n
    return m

  res = []
  k = max(A)
  ind = A.index(k)
  for i in range(N):
    if i != ind:
      res.append(gcd(A[i], k))
  print(max(res))

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

As = sorted(As)[::-1]
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:
def GCD(a, b):
    while a % b != 0:
        r = a % b
        a, b = b, r
    return b

ans = 0
N = int(input())
A = tuple(map(int,input().split()))
A2 = tuple(set(A))

if len(A2) <= 2:
    A2 = (A2[0],A2[0])

for i in range(len(A2)-1):
    for j in range(i+1,len(A2)):
        ans = max(ans,GCD(A2[i],A2[j]))

print(ans)

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)
if c[max_gcd] >= n-2:
    print(max_gcd)
else:
    print(c.most_common()[0][0])

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
 
N = int(input())
a_list = list(map(int, input().split()))
ans = []
for i in range(N-1):
    b = gcd(a_list[i], a_list[i+1])
    ans.append(b)
if N > 2:
    b = gcd(a_list[0], a_list[N-1])
    ans.append(b)
if N == 2:
    print(max(a_list))
elif N == 3:
    print(max(ans))
else:
    ans.sort()
    print(ans[2])

Submission status: Wrong Answer

Solution code:
import fractions

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

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

gcd.append(fractions.gcd(A[0], A[number-1]))

gcd.sort(reverse=True)

if gcd[0] == gcd[number-1]:
    print(gcd[0])

elif gcd[number-2] == gcd[number-1] and gcd[number-3] != gcd[number-2]:
    print(gcd[number-3])
    
elif gcd[number-3] == gcd[number-2] and gcd[number-2] != gcd[number-1]:
    print(gcd[number-2])

else:
    print(gcd[number-1])

Submission status: Wrong Answer

Solution code:
from functools import reduce

dic = {}
def gcd(x, y):
  if (x, y) in dic:
    return dic[(x, y)]
  if y == 0:
    return x
  else:
    dic[(x, y)] = gcd(y, x % y)
    return dic[(x, y)]

def gcd_list(numbers):
  return reduce(gcd, numbers)
 
n = int(input())
li = list(set(map(int, input().split())))

n = len(li)
ans = []
if n == 1:
  ans = li.copy()
else:
  for i in range(n):
    du = li.copy()
    del du[i]
    ans.append(gcd_list(du))

print(max(ans))

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 < 100:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in range(100):
    t = gcd(random.sample(a, 50))
    if ans < t:
      ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import functools
import fractions

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

if max(v) % 2 ==0:
	b = True
else:
	b = False
		
v.sort()

for index,_ in enumerate(v):
	if _  % 2 ==0:
		if not b:
			v[index] = v[-1]
			break
			
	else:
		if b:
			v[index] = v[-1]
			break
				
#ans = functools.reduce(math.gcd,v)
ans = v[-1]
for i in range(1,len(v)):
	ans = fractions.gcd(ans, v[i])
	
print(ans)

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) >= 4:
    for lop in range(1,len(A),2):
        print(A[lop-1],A[lop])
        Al.append( fractions.gcd(A[lop-1],A[lop]) )
    if len(A) %  2 == 1:
        Al.append( fractions.gcd(A[len(A)-2],A[len(A)-1]) )
    Al.sort()
    if Al[0] == Al[1]:
        print(Al[2])
    else:
        print(Al[1])
elif len(A) == 3:
    A1 = fractions.gcd(A[0],A[1])
    A2 = fractions.gcd(A[0],A[2])
    A3 = fractions.gcd(A[1],A[2])
    print(max(A1,A2,A3))
else:
    print(max(A))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
Alist = np.array(list(map(int, input().split())))

def gcd(nlist):
    tmp = nlist[0]
    while len(nlist) != 0:
        nlist = np.sort(nlist)
        tmp = nlist[0]
        nlist = nlist % tmp
        nlist = nlist[nlist != 0]
    return tmp

gcdlist = []
for i in range(len(Alist)):
    if len(Alist) == 1:
        nlist = Alist[0]
        gcdlist.append(nlist)
    else:
        nlist = np.append(Alist[:i], Alist[i+1:])
        gcdlist.append(gcd(nlist))
print(max(gcdlist))

Submission status: Wrong Answer

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


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

def main():
    n = int(input())
    A = [int(e) for e in input().split(" ")]

    max_n = 0
    for i in range(n):
        if i < max_n:
            continue
        for j in range(i+1, n):
            current = gcd(A[i], A[j])
            if max_n < current:
                max_n = current

    if max_n == 0:
        max_n = gcd(max(A), 1000000000)

    print(max_n)

main()

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[0],nums[1]), gcd(nums[1],nums[2]), gcd(nums[0],nums[2])))

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = sorted(li_input(), reverse=True)

    ans = 10**100
    ans_i = -1

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

        if g < ans:
            ans = g
            ans_i = i

    print(max(
        gcd_list(A[:-1]),
        gcd_list(A[:ans_i] + A[ans_i+1:])
    ))


main()

Submission status: Wrong Answer

Solution code:
import functools
import fractions
import math
import numpy as np
import statistics


N = int(input())
A = list(map(int, input().split()))
A.sort()
gcd = functools.reduce(fractions.gcd, A)
A_med = statistics.median_low(A)
del A[A.index(A_med)]
gcd_new = functools.reduce(fractions.gcd, A)
if gcd_new >= gcd:
    gcd = gcd_new
print(gcd)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
A.sort()
A.append(A[N-1])
G = []
for i in range(N-1):
    G.append(gcd(A[i],A[i+1]))
G.append(gcd(A[N-1],A[0]))
H = G.copy()
G.sort()
index = bisect.bisect_right(H,G[0])-1
A[index] = A[index+1]
K = []
for i in range(N-1):
    K.append(gcd(A[i],A[i+1]))
K.sort()
print(K[0])

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]

        if gcd == 1:
            print(1)
            exit()

print(gcd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n == 2:
    print(gcd(*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:
def gcd(x, y):
	if y == 0:
		return x;
	else:
		x %= y;
		x, y = y, x;
		return gcd(x, y);



N = input();
A = map(int, raw_input().split())

max_gcd = 0;


if (N == 2):
	print(max(A));

else:
	for i in range(N):
		for j in range(i+1,N):
			
			g = gcd(A[i],A[j]);

			if max_gcd < g:
				max_gcd = g;

	print(max_gcd);

Submission status: Wrong Answer

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

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


      
      
x = a[0]
for i in range(n):
    x = gcd(x,a[i])

m = x
y=a[0]

for i in range(n):
    if m<gcd(x,a[i]):
        y = a[i]
        m=gcd(x,a[i])
a.remove(y)
x = a[0]
for i in range(n-1):
    x = gcd(x,a[i])
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
ans = 1
for i in range(N):
  flag = True
  if i == 0:
    p = A[1]
    for j in range(2,N):
      p = gcd(A[i],p)
      if ans >= p:
        flag = False
        break
    if flag:
      ans = p
  else:
    p = A[0]
    if p != 1:
      for j in range(1,N):
        if j != i:
          p = gcd(A[i],p)
        if ans >= p:
          flag = False
          break
      if flag:
        ans = p
    else:
      p = A[1]
      for j in range(2,N):
        if j != i:
          p = gcd(A[i],p)
        if ans >= p:
          flag = False
          break
      if flag:
        ans = p
print(ans)

Submission status: Wrong Answer

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

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

mm = 0
for i in range(N):
  for j in range(i+1,N):
    g = gcd(A[i],A[j])
    if mm <= g:
      mm = g
    else:
      break
    #print(i,j,g)
    
print(mm)

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 not len(A)==2:
    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)
else:
    ans_list.append(gcd(A[0],A[1]))
print(max(ans_list))

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[2])

Submission status: Wrong Answer

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

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

A.sort()
inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i

# A[0]以外
check2 = A[1]
for i in range(0,N):
    check2 = gcd(check2, A[i])

ans = check2

# check以外
if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        if i == 0:
            check3 = A[0]
        else:
            check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

gcd.append(fractions.gcd(A[0], A[number-1]))

gcd.sort(reverse=True)
print(gcd)
if gcd[0] == gcd[number-1]:
    print(gcd[0])

elif gcd[number-2] == gcd[number-1] and gcd[number-3] != gcd[number-2]:
    print(gcd[number-3])
    
elif gcd[number-3] == gcd[number-2] and gcd[number-2] != gcd[number-1]:
    print(gcd[number-2])

else:
    print(gcd[number-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
As.sort(reverse=True)
first_d = As[0]
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

if N == 2:
    print(max(As))
else:
    first = make_divisors(As[0])
    second = make_divisors(As[1])
    third  = make_divisors(As[2])
    div_list = list((set(first) & set(second)) | (set(first) & set(third)) | (set(third) & set(second)))
    div_list.sort(reverse=True)
    
    for d in range(len(div_list)):
        cnt = 0
        for i in range(N):
            if As[i] % (div_list[d]) != 0:
                cnt += 1
                if cnt > 1:
                    break
        ans = div_list[d]
        break
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import math
N = int(input())
A = list(map(int, 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(reverse=True)
    return divisors

min_a = min(A)

div = make_divisors(min_a)
c = 0
for i in div:
    for a in A:
        if a % i == 0:
            c += 1
    if c == N-1 or c == N:
        print(i)
        break
    c = 0

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)


def list_gcd(a):
    a_gcd = a[0]
    for i in range(n-1):
        a_gcd = gcd(a_gcd, a[i+1])
    return a_gcd


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

ans = list_gcd(a)

for i in range(n):
    b = a[:]
    if b[i] % 2 != 0:
        b[i] = b[i-1]
        ans = max(ans, list_gcd(b))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
num_unique = list(set(num_list))
num_unique.sort()
num_unique.reverse()
max_num = 0
flag = False
for i in range(num_unique[-1], 0, -1):
    if flag and count < 2:
        break
    elif i == 1:
        max_num = 1
        break
    else:
        flag = True
        count = 0
        max_num = i
    for num in num_unique:
        if int(num / max_num) < 1 or num % max_num != 0:
            count += 1
            if count > 1:
                break
print(max_num)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(sys.getrecursionlimit())
N = int(input())
A = list(map(int,input().split(" ")))

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b

gcdForward = [0] * N
gcdBackWard = [0] * N
gcdForward[0] =  A[0]
gcdBackWard[N-1] = A[-1]
for i in range(N-1):
    gcdForward[i+1] = gcd(gcdForward[i],A[i+1])
    gcdBackWard[N-i-2] = gcd(gcdBackWard[N-i-1],A[N-i-2])


if N == 2:
    print(max(A))
    exit(0)
else:
    ans = max(gcdBackWard[1],gcdForward[N-2])
    for i in range(1,N-1):
        print(i-1,i+1)
        ans = max(ans,gcd(gcdForward[i-1],gcdBackWard[i+1]))
    print(ans)

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:
      d=gcd(d,a[i+1])
  print(d)

Submission status: Wrong Answer

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

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

sa_list = []
for i in range(n-1):
    sa_list.append(A[i+1]-A[i])
del A[sa_list.index(min(sa_list))+1]

n -=1

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

Submission status: Wrong Answer

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

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



if N == 2:
    print(max(a))
else:

    small = 1
    x = a[0]
    x2 = a[1]
    big = N - 2
    y = a[-1]
    i, j, k = gcd(x, x2), gcd(x, y), gcd(x2, y)
    if i < k and j < k:
        x = a[1]
        a[1], a[0] = a[0], a[1]
    elif k < i and j < i:
        y = a[1]
        a[1], a[-1] = a[-1], a[1]
    while small < big:
        if gcd(a[small], x) < gcd(a[big], y):
            y = gcd(a[big], y)
            big -= 1
        else:
            x = gcd(a[big], x)
            small += 1

    print(gcd(x, y))

Submission status: Wrong Answer

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

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

result = 1
a[0] = a[1]

for i in range(n-1):
    for j in range(i+1,n):
        if(a[i] >= a[j]):
            result = gcd(a[i], a[j])
        elif(a[i] < a[j]):
           result = gcd(a[j], a[i])
        if (result == 1):
            break

print(result)

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

As = sorted(As)[::-1]
## 0 
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):
    a = sum([a%dev==0 for a in As])
    if N - a == 0 or N -a == 1:
        ans = dev
print(ans)

Submission status: Wrong Answer

Solution code:

def gcd(a, b):
    while a>0 and b >0:
        if a > b:
            a %= b
        else:
            b %= a
    return a + b

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

forwards = [A[0]]
backwards = [A[-1]]
for i in range(N):
    forwards.append(gcd(forwards[-1], A[i]))
    backwards.append(gcd(backwards[-1], A[-(i+1)]))
backwards = list(reversed(backwards))

ans = 0
for i in range(1, N-1):
    a = gcd(forwards[i-1], backwards[i+1])
    if a > ans:
        ans = a

if N > 2:
    ans = max([ans, forwards[-2], backwards[1]])
elif N == 2:
    ans = max(A)
else:
    ans = A[0]

print(ans)

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=list(set(ans))
ans.sort()
if len(ans)>1:
    print(ans[1])
else:
    print(ans[0])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(sys.getrecursionlimit())
N = int(input())
A = list(map(int,input().split(" ")))

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b

gcdForward = [0] * N
gcdBackWard = [0] * N
gcdForward[0] =  A[0]
gcdBackWard[N-1] = A[-1]
for i in range(N-1):
    gcdForward[i+1] = gcd(gcdForward[i],A[i+1])
    gcdBackWard[N-i-2] = gcd(gcdBackWard[N-i-1],A[N-i-2])
print(gcdForward)
print(gcdBackWard)

if N == 2:
    print(max(A))
    exit(0)
else:
    ans = max(gcdBackWard[1],gcdForward[N-2])
    for i in range(1,N-1):
        print(i-1,i+1)
        ans = max(ans,gcd(gcdForward[i-1],gcdBackWard[i+1]))
    print(ans)

Submission status: Wrong Answer

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

divs = {}
for A_i in A:
    #    for i in range(1, int(A_i ** 0.5) + 1):
    for i in range(1, 1000):
        if A_i % i == 0:
            if i in divs:
                divs[i] += 1
            else:
                divs[i] = 1
            if i != A_i // i:
                if A_i // i in divs:
                    divs[A_i // i] += 1
                else:
                    divs[A_i // i] = 1
divs = sorted(divs.items(), key=lambda x: x[0], reverse=True)

for divs_i in divs:
    if divs_i[1] == N or divs_i[1] == N - 1:
        print(divs_i[0])
        break

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().split()))

result = 0

for i in range(N):
    array = A[:i]
    if i < N - 1:
        array.append(A[i+1])
        array.extend(A[i+1:])
    else:
        array.append(A[0])
        
    x = array[0]
    for j in range(1, N):
        x = gcd(x, A[j])

    result = max(result, x)

print(result)

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_1 != 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))