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: Runtime Error

Solution code:
import sys
import os
import math
import fractions
from functools import reduce
from fractions import gcd

def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    #print("XX=",XX)
    return XX

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

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

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

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

n=int(input())
array = list(map(int, input().split())) 
array=list(set(array))
array.sort(reverse=True)
min=array[-1]

max=-100

for i in range(n):
    copy_array=array.copy()
    if(max>array[i]):
        break
    copy_array.pop(i)

    tmp_gcd=gcd(*copy_array)
    
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    
print(max)

Submission status: Runtime Error

Solution code:
import math
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
      
n=int(input())
a=list(map(int, input().split()))
dl = []
for i in range(n):
  dl.append(make_divisor_list(a[i]))

ind = -1
while(1):
  cnt = 0
  ma= dl[0][0]
  for i in range(1, n):
    if ma < dl[i][ind]:
      ma = dl[i][ind]
  for i in range(n):
    if ma in dl[i]:
      cnt += 1
  if cnt == n-1:
    memo = ma
    break
  elif cnt == n:
    memo = ma
    break    
  else:
    ind += -1
    
print(ma)

Submission status: Runtime Error

Solution code:
import fractions
import itertools

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

al = list(itertools.combinations(l, 2))

ansl = []

for j in range(len(al)):
    a = list(al[j])
    ans = a[0]
    for i in range(1, n-1):
        ans = fractions.gcd(ans, a[i])
    ansl.append(ans)
    
print(max(ansl))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
A = [int(i) for i in input().split(" ")]
if N>2:
    g1 = math.gcd(A[0],A[1])
    g2 = max(math.gcd(A[0],A[2]),math.gcd(A[1],A[2]))
    cand1 = max(g1,g2)
    cand2 = min(g1,g2)
    flag = False
    for n,i in enumerate(A[3:]):
        g = math.gcd(cand1,i)
        if g < cand1:
            if flag:
                if g==cand2:
                    pass
                else:
                    cand1 = max(g,cand2)
                    cand2 = min(g,cand2)
                flag = False
            else:
                flag =True
        else:
            cand2 = cand1
            cand1 = g
    print(cand1)
else:
    print(max(A[0],A[1]))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=list(set(A))
max=10**9
for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5+1
    for j in range(1,int(a)):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(int(A[i]/j))
    A[i]=divesor
    if max>max(A[i]):
        max=max(A[i])
for i in range(max,0,-1):
    flag=1
    for j in range(N):
        if i not in A[j]:
            flag-=1
    if flag >=0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
import copy
import functools
import math

N = input()
str_A = input()

str_A = str_A.split()

A = []

for i in str_A:
    A.append(int(i))

origin_list = copy.deepcopy(A)
# gcd = []
max_gcd = 0
kesusoezi = 0

for i in range(len(A)):
    A.pop(i)
    gcd = functools.reduce(math.gcd, A)
    A = copy.deepcopy(origin_list)
    if max_gcd < gcd:
        kesusoezi = i
        max_gcd = gcd

A = copy.deepcopy(origin_list)

kotae = functools.reduce(math.gcd, A)

A[kesusoezi] = max_gcd

kotae = functools.reduce(math.gcd, A)

# print(kesusoezi)
print(kotae)

Submission status: Runtime Error

Solution code:
import numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
def gcd2(A):
    r = gcd(A[0],A[1])
    for i in range(len(A)-2):
        r = gcd(A[i+2],r)
    return r
S = list()
for i in range(N):
    k = A.pop(i)
    S =np.append(S,gcd2(A))
    A.insert(i,k)
print int(max(S))

Submission status: Runtime Error

Solution code:
import math
import os
import random
import re
import sys
from collections import defaultdict


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



def solve(n, a):
    if n < 1:
        return 0
    if n == 1:
        return n[0]
    if n == 2:
        return gcd(a[0], a[1])

    dp = [False for _ in range(10001)]

    gcd0 = gcd(a[0], a[1])
    dp[gcd0] = True
    gcd1 = gcd(gcd0, a[2])
    if gcd1 == gcd0:
        zero = gcd(a[1], a[2])
        one = gcd(a[0], a[2])
        if zero > one:
            dp[zero] = True
            gcd0 = zero
        else:
            dp[one] = True
            gcd0 = one

    for i in range(1,n):
        gcd0 = gcd(gcd0, a[i])
        dp[gcd0] = True

    count = 0
    start = 0
    for i in range(len(dp)):
        if dp[i] == True:
            start = i
            break
    if start == len(dp):
        return start - 1
    for i in range(start+1, len(dp)):
        if dp[i] == True:
            return i
    return start

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(n,a))

Submission status: Runtime Error

Solution code:
import fractions

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

al = list(itertools.combinations(l, 2))

ansl = []

for j in range(len(al)):
    a = list(al[j])
    ans = a[0]
    for i in range(1, n-1):
        ans = fractions.gcd(ans, a[i])
    ansl.append(ans)
    
print(max(ansl))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import math
data = {}


def solve(n, a):
    if n == 2 and a[0] == a[1]:
        return a[0]
    n_dict = defaultdict(int)
    for i in range(len(a)):
        for j in range(len(list(a)) - i + 1):
            n_dict[math.gcd(a[i], a[j + i - 1])] += 1
    return sorted(n_dict.items(), key=lambda x: x[0])[1][0]


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
list_a = list(map(int, input().split()))  # この中から一つを選んで 1~10^9 以下の好きな整数に書き換える
# 書き換えた後のlist_aの整数の最大公約数の最大値は？

result = reduce(math.gcd, list_a)
# 一つを除いた最大公約数のうち最も大きいものを求める
for i in range(n):
    copied = list_a.copy()
    del copied[i]
    gcd = reduce(math.gcd, copied) if len(copied) > 1 else copied[0]
    if gcd > result:
        result = gcd

print(result)

Submission status: Runtime Error

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

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

if N == 2:
    if A[0] > A[1]:
        print(A[0])
    else:
        print(A[1])
else:
    gcd_max = 0
    for i in range(N):
        if i != 0:
            gcd_temp = A[0]
        else:
            gcd_temp = A[1]
        j = 0
        while j != N:
            if j != i:
                gcd_temp = gcd(gcd_temp, A[j])
            if gcd_temp == 1:
                j += N
            j += 1
        if gcd_max < gcd_temp:
            gcd_max = gcd_temp
    print(gcd_max)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = sorted(input().split(" "))
    ans = [0]*N
    for i in range(N):
        tmp = A[i]
        if (i == N-1):
            A[i] = A[N-2]
        else :
            A[i] = A[N-1]
        ans.append(recursive_gcd(N,A))
        A[i] = tmp
    print(max(ans))


def recursive_gcd(n,array):
    if (n <= 2):
        return gcd_euclid(int(array[0]),int(array[1]))
    else:
        return gcd_euclid(recursive_gcd(n-1,array),int(array[n-1]))

# http://d.hatena.ne.jp/sh-2/20100320/1269039543 から引用
def gcd_euclid(u, v) :
  while (0 != v) :
    r = u % v
    u = v
    v = r
  return u
#引用ここまで

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Solution code:
import math
from functools import reduce
import copy

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

numNum = int(input())
setOfNumOrg = input().split()
setOfNum = [int(i) for i in setOfNumOrg]

ans = 1
#二つの場合
if numNum == 2:
    ans = max(setOfNum)
else:
#一つづつ順に欠損させていきそのなかの最大に合わせればいい
    for i in range(numNum):
        copyData = copy.copy(setOfNum)
        del copyData[i]
        if gcd(*copyData) > ans:
            ans = gcd(*copyData)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
A = [int(i) for i in input().split(" ")]
if N>2:
    g1 = math.gcd(A[0],A[1])
    g2 = max(math.gcd(A[0],A[2]),math.gcd(A[1],A[2]))
    cand1 = max(g1,g2)
    cand2 = min(g1,g2)
    flag = False
    for n,i in enumerate(A[3:]):
        g = math.gcd(cand1,i)
        print(cand1)
        if g < cand1:
            if flag:
                if g==cand2:
                    pass
                else:
                    cand1 = max(g,cand2)
                    cand2 = min(g,cand2)
                flag = False
            else:
                flag =True
        else:
            cand2 = cand1
            cand1 = g
            print(cand1)
    print(cand1)
else:
    print(max(A[0],A[1]))

Submission status: Runtime Error

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

def mygcd(A):
    if len(A) == 1:
        return A[0]
    else:
        return math.gcd(A[0],mygcd(A[1:]))
        
ans = []
for i in range(N):
    ans.append(mygcd(A[:i]+A[i+1:]))

print(max(ans))

Submission status: Runtime Error

Solution code:
import math
import itertools
from functools import reduce


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


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

C = list(itertools.combinations(A, N - 1))

num_max = 0
for i in range(len(C)):
    temp = gcd(*C[i])
    if temp > num_max:
        num_max = temp

print(num_max)

Submission status: Runtime Error

Solution code:
import math
import copy
n=int(input())
num=list(map(int,input().split()))

def hcfnaive(a,b): 
  if(b==0): 
    return a 
  else: 
    return hcfnaive(b,a%b) 
      
def gcd(numbers):
  if len(numbers)==2:
    return hcfnaive(numbers[0],numbers[1])
  elif len(numbers)==1:
    return numbers[0]
  else:
    numbers[0]=hcfnaive(numbers[0],numbers[1])
    numbers.pop(1)
  	return gcd(numbers)

ans=0
for i in range(n):
  num2=copy.deepcopy(num)
  num2.pop(i)
  ab=gcd(num2)
  if ab>ans:
    ans=ab
print(ab)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*nums):
    return reduce(math.gcd, nums)

max = 0

N = int(input())

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

for i in range(N):
    A_ = A[:]
    A_.pop(i)
    A_without_ith = A_
    gcd_ = gcd(*A_without_ith)
    max = gcd_ if gcd_ > max else max

print(max)

Submission status: Runtime Error

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

N = input()
As =  list(map(int, input().split()))
sorted(As, reverse=True)
ans = As[0]
r = []
for a in As[1:]:
  r.append(gcd(ans, a))
print(max(sorted(r)[1:]))

Submission status: Runtime Error

Solution code:
def saidai(a,b):
    amari = a % b
    if amari != 0:
        return saidai(b,amari)
    else:
        return b
def saidai_f(a):
    a.sort(reverse=True)
    if len(a) == 1:
        return a[0]
    a.insert(0,saidai(a.pop(0),a.pop(0)))
    return saidai_f(a)

ans=[]
hoge=[]
n=int(input())
a=list(map(int,input().split()))

for i in range(n):
    for ii in range(n):
        if i!=ii:
            hoge.append(a[ii])
    hoge.sort(reverse=True)
    ans.append(saidai_f(hoge))
    hoge=[]
ans.sort(reverse=True)
print(ans[0])

Submission status: Runtime Error

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

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)

Submission status: Runtime Error

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: Runtime Error

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

def GCD(m, n):
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

import numpy as np

B = np.ones((N, N)) * 10 ** 10

for m in range(N):
  for n in range(m, N):
    if m == n:
      B[m, m] = 0
    else:
      B[m, n] = B[n, m] = GCD(A[m], A[n])

C = B.sum(axis=1)
idx = C.argmin()

B = np.where(B == 0, 10 ** 10, B)
B = np.delete(B, idx, axis=0)
B = np.delete(B, idx, axis=1)
print(int(B.min()))

Submission status: Runtime Error

Solution code:
num = input()
num = int(num)
tar = input().split()
cnt = 0
aaa = 0
tmp = []

nyan = int(tar[0])

for i in range(num):
  tar[i] = int(tar[i])
  if nyan < tar[i]:
    nyan = tar[i]
    aaa = i

for i in range(1,nyan):
  for j in range(num):
    if tar[j]/2 < i:
      break
    if tar[j]%i == 0:
      cnt +=1
  cnt +=1
  if cnt >= num:
    tmp.append(i)
  cnt = 0

print(tmp[len(tmp)-1])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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: Runtime Error

Solution code:
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce

n = int(input())
a = input()
a = re.split(" ",a)
a = list(map(int,a))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Submission status: Runtime Error

Solution code:
#C - GCD on Blackboard
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcdList(num):
    if len(num) == 1:
        return num[0]
    else:
        return gcd(num.pop(), gcdList(num))
    
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans = max(ans, gcdList(a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

num=0
x=A[0]
for i in range(N):
    x=A[i]
    A[i]=max(A)
    num=max(num,reduce(math.gcd,A))
    A[i]=x
print(num)

Submission status: Runtime Error

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(N-1):
    for j in range(i+1,N):
        ans = max(ans,GCD(A2[i],A2[j]))

print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 2:
    print(max(A))
    exit()
result = []
num = 0
for a in A[1:]:
    if a % A[0] != 0:
        num += 1
        if num == 2:
            break
else:
    result.append(A[0])
for n in range(2, int(math.sqrt(A[0])) + 1):
    if A[0] % n != 0:
        continue
    num = 0
    for a in A[1:]:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(n)
    num = 0
    x = A[0] // n
    for a in A[1:]:
        if a % x != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(x)
num = 0
for a in A[0:1] + A[2:]:
    if a % A[1] != 0:
        num += 1
        if num == 2:
            break
else:
    result.append(A[1])
for n in range(2, int(math.sqrt(A[1])) + 1):
    if A[1] % n != 0:
        continue
    num = 0
    for a in A[0:1] + A[2:]:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(n)
    num = 0
    x = A[1] // n
    for a in A[0:1] + A[2:]:
        if a % x != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(x)
print(max(result))

Submission status: Runtime Error

Solution code:
import math
import sys
import collections
from functools import reduce

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

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(sys.stdin.readline())
A = sys.stdin.readline().strip().split()
A = list(map(int, A))

#print(A)
if(N==2):
    print(max(A))
else:
    m = []
    for i in range(N):
        An = A[:]
        An.pop(i)
        m.append(gcd_list(An))
#        print(An)
    #print(m)
    print(max(m))

Submission status: Runtime Error

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

for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5+1
    for j in range(1,int(a)):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(int(A[i]/j))
    A[i]=divesor
for i in range(max,0,-1):
    flag=1
    for j in range(N):
        if i not in A[j]:
            flag-=1
    if flag >=0:
        print(i)
        break

Submission status: Runtime Error

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:
    print(max(a_list))
else:
    ans.sort()
    print(ans[2])

Submission status: Runtime Error

Solution code:
import math 
N = int(input())
A= list(map(int,input().split()))
memo_gcd_foward = [A[0]]
memo_gcd_backward = [A[N-1]]

for i in range(N-1):
    memo_gcd_foward.append(math.gcd(memo_gcd_foward[-1],A[i+1]))

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


cand = []
cand.append(memo_gcd_foward[-1])
cand.append(memo_gcd_foward[-2])
cand.append(memo_gcd_backward[-2])

for i in range(N-2):
    cand.append(math.gcd(memo_gcd_foward[i],memo_gcd_backward[-i-3]))
print(max(cand))

Submission status: Runtime Error

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

maxAns = min(A)

# ゴリおす。最小のAから1ずつ減らして、割り切れなかったAが1個以下だったらそこが解答

for i in range(maxAns):
    acount = 0
    for Ai in A:
        if Ai % (maxAns - i) != 0:
            acount += 1
    # 割り切れなかった回数を数える
    if acount <= 1:
        print(maxAns - i)
        exit()

# 必ず止まるはずだけど保険。
print(1)

Submission status: Runtime Error

Solution code:
import math
import copy
n=int(input())
num=list(map(int,input().split())).sort(reverse=True)

def hcfnaive(a,b): 
  if(b==0): 
    return a 
  else: 
    return hcfnaive(b,a%b) 
      
def gcd(numbers):
  if len(numbers)==2:
    return hcfnaive(numbers[0],numbers[1])
  elif len(numbers)==1:
    return numbers[0]
  else:
    numbers[0]=hcfnaive(numbers[0],numbers[1])
    numbers.pop(1)
  return gcd(numbers)

ans=0
for i in range(n):
  num2=copy.deepcopy(num)
  num2.pop(i)
  ab=gcd(num2)
  if ab>ans:
    ans=ab
print(ab)

Submission status: Runtime Error

Solution code:
import math
import sys

sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A.sort()
mx = 10 ** 9
idx = 0
g = []
for i in range(N-1):
    tmp = math.gcd(A[i], A[i+1])
    #print(A[i], A[i+1], tmp)
    if tmp < mx:
        mx = tmp
        idx = i
    g.append([tmp, i])
g.sort(key=lambda x:x[0])
#print(g)
if N > 2:
    if g[0][1] + 1 == g[1][1]:
        A.remove(A[g[0][1]+1])
    else :
        tmp1 = math.gcd(A[g[0][1]], A[g[1][1]])
        tmp2 = math.gcd(A[g[0][1]+1], A[g[1][1]])
        A.remove(A[g[0][1]] if tmp1 < tmp2 else A[g[0][1]+1])
else :
    A = [max(A)]
tmp = A[0]
for i in A:
    tmp = math.gcd(i, tmp)
#import functools
#print(functools.reduce(math.gcd, A))
print(tmp)

Submission status: Runtime Error

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)

if N ==2:
    print(max(A))
else:
    A_pattern = []
    ans = []
    for i in range(N):
        a = A[:]
        a.remove(A[i])
        A_pattern.append(a)
    N -=1

    for A in A_pattern:
        g = gcd(A[0], A[1])
        for i in range(2, N-1):
            g = gcd(gcd, A[i])
        ans.append(g)
    print(max(ans))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = []
tmp = input().split()
for i in range(n):
    a.append(int(tmp[i]))

if n == 2:
    if a[0] > a[1]:
        print(a[0])
    else:
        print(a[1])
    exit()

rev = []
rev.append(a[n-1])
prev_gcd = a[n-1]
for i in range(n-2, 0, -1):
    prev_gcd = math.gcd(prev_gcd, a[i])
    rev.append(prev_gcd)

ans = math.gcd(a[0], rev[-2])
if ans < rev[-1]:
    ans = rev[-1]
        
prev_gcd = a[0]
for i in range(1, n-1):
    prev_gcd = math.gcd(prev_gcd, a[i])
    cand_ans = math.gcd(prev_gcd, rev[-1 - i])
    if cand_ans > ans:
        ans = cand_ans

print(ans)

Submission status: Runtime Error

Solution code:
#C
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
N=int(input())
A = [int(j) for j in input().split()]
A=list(set(A))
A.sort()
ans=0


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

if len(A)==2:
    ans =max(ans,gcd(A[0],A[1]))
    print(ans)
    exit()
    
for a in A:
    tmp=A.copy()
    tmp.remove(a)
    ans =max(ans,gcd(*tmp))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

max_gcd = 1
for i in range(N):
        tmp_list =[]
        tmp_list.extend(A[:i])
        tmp_list.extend(A[i+1:])
        tmp_gcd = gcd(tmp_list)
        if max_gcd < tmp_gcd:
                max_gcd = tmp_gcd

print(max_gcd)

Submission status: Runtime Error

Solution code:
import math
import queue

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

ques = [queue.Queue() for i in range(N)]

for i, Ai in enumerate(As):
    qi = ques[i]
    for j in range(1,int(Ai/2)+1) :
        if (Ai % j == 0) :
            qi.put(j)
    
flag = True
while flag:
    for i, qi in enumerate(ques):
        if(qi.empty()) :
            As[i] = As[-1]
            flag = False
            break
        else :
            qi.get()

min_num = As[0]
gcd_num = math.gcd(As[0], As[1])
for i in range(2,N) :
    #改善の余地あり
    gcd_num = math.gcd(gcd_num, As[i])
    if (gcd_num==1) :
        break

print(gcd_num)

Submission status: Runtime Error

Solution code:
import copy

tmp = 0
Max = 1

N = int(input())

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

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

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)

Submission status: Runtime Error

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(ans[1] if N == 1 else ans[2])

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int, input().split()))
Z=0
for i in range(N):
    if i==0:
        ans=A[1]
        for j in range(2,N):
            ans=math.gcd(ans,A[j])


    else :
        B=A.copy()
        B[i]=B[0]
        Z=B[0]
        for k in range(1,N):
            Z =math.gcd(Z,B[k])


    if ans >Z:
        ans=ans
    else:
        ans=Z

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

res = 0
for i in range(n):
    a = x.copy()
    b = a.pop(i)
    c = gcd_list(a)

    d = x.copy()
    d[i] = c
    if  res < gcd_list(d):
        res = gcd_list(d)
print(res)

Submission status: Runtime Error

Solution code:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from collections import Counter
from functools import reduce
inf = 10**10
import sys
input = sys.stdin.readline
def gcd_list(numbers):
    return reduce(math.gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
index = inf
if n == 2:
    print(max(a))
else:
    a.sort()
    if math.gcd(a[0],a[n-1]) == 1:
        print(max(gcd_list(a[1:n]),gcd_list(a[0:n-1])))
    else:
        for i in range(1,n-1):
            ans = math.gcd(a[0],a[n-1])
            if math.gcd(a[i]-a[0],a[n-1]-a[i]) <= ans:
                index = i
                ans = math.gcd(a[i]-a[0],a[n-1]-a[i])
        print(gcd_list(a[0:i]+a[i+1:n]))

Submission status: Runtime Error

Solution code:
import math
import copy
n=int(input())
num=list(map(int,input().split()))

def hcfnaive(a,b): 
  if(b==0): 
    return a 
  else: 
    return hcfnaive(b,a%b) 
      
def gcd(numbers):
  if len(numbers)==2:
    return hcfnaive(numbers[0],numbers[1])
  elif len(numbers)==1:
    return numbers[0]
  else:
    numbers[0]=hcfnaive(numbers[0],numbers[1])
    numbers.pop(1)
  return gcd(numbers)

ans=0
for i in range(n):
  num2=copy.deepcopy(num)
  num2.pop(i)
  ab=gcd(num2)
  #if ab>ans:
  #  ans=ab
print(ab)

Submission status: Runtime Error

Solution code:
import math

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

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-1):
        m.append(gcd(a[i],a[i+1]))
    m.append(gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])

Submission status: Runtime Error

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

N = int(input())
A = np.array(input().split()).astype(int)

def gcd(numbers):
    return reduce(fractions.gcd, numbers)
rt = 1
for i in range(N):
    a = A[i]
    A[i] = 0
    f = gcd(A_tmp[A_tmp>0])
    A[i] = a
    if rt < f:
        rt = f
print(rt)