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: Time Limit Exceeded

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, n-1))
    if ans < t:
      ans = t

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

N=int(input())

k=[0]*N

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

for i in range(N):

    c=b.pop(0)
    k[i]=gcd_list(b)
    b.append(c)

print(max(k))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

for i in range(n):
  tmp = gcd_list(a[i+1:]+a[:i])
  if tmp > v:
    v = tmp
print(v)

Submission status: Time Limit Exceeded

Solution code:
import functools
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def gcd_l(l):
  tmp = l[0]
  for i in range(len(l)):
    tmp = gcd(tmp, l[i])
  return tmp
for i in range(n):
  ans[i] = gcd_l(a[:i] + a[i+1:])
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc125/tasks/abc125_c

import math

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

i=2
b=[1]#a=0
c=[1]
#d=[]
while True:
    a = 0
    for j in range(N):
        if A[j] % i != 0:
            a += 1
        #print(i,A[j],a)
        if a > 1:
            break

    if a == 0:
        b.append(i) #white list
        for j in range(len(A)):
            A[j] = int(A[j] / i)
        i = 2
    if a == 1:
        c.append(i) #gray list
    if a > 0:
        i += 1

    if i > min(A):
        break

bs = 1
for i in range(len(b)):
    bs *= b[i]
print(bs * max(c))

'''
a=[]
for i in range(0,N,2):
    if i == N-1:
        a.append(A[i])
        break
    else:
        a.append(math.gcd(A[i],A[i+1]))
'''

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import copy
def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y) #再帰定義
  
def gcd_list(numbers):
    return reduce(gcd, numbers)
  
n=int(input())
a_o=list(map(int,input().split()))
g=[1]*n
for i in range(n):
  a=copy.copy(a_o)
  a.pop(i)
  g[i]=gcd_list(a)
print(max(g))

Submission status: Time Limit Exceeded

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

num = int(input())
int_list = np.array(list(map(int, input().split())))

# 任意のN-1個の組み合わせの最大公約数を求めればいい
combination = list(itertools.combinations(int_list,num - 1))
output = 0
# for c_list in combination:
#     _c_list = sorted(list(c_list))

#     min_ai = min(_c_list)

#     g_common_divisor = 1
#     for i in range(1, int(min_ai / 2) + 1):
#         flag = 0
#         for num in _c_list:
#             if num % i != 0:  # iで割り切れなければiは公約数じゃない
#                 flag = 1
#                 continue
#         if flag == 0:
#             g_common_divisor = i
#         print(c_list, i, flag, g_common_divisor)
#     if output < g_common_divisor:
#         output = g_common_divisor
# print(output)

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

for c_list in combination:
    _c_list = sorted(list(c_list))

    min_ai = min(_c_list)

    g_common_divisor = gcd_list(_c_list)
    if output < g_common_divisor:
        output = g_common_divisor
print(output)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

def divisors():
    for i in range(B[0], 0, -1):
        if any(map(lambda n: n%i==0, B)):
            yield i

ans = 1
divs = divisors()
for d in divs:
    count = 0
    for a in A:
        if a % d != 0:
            count += 1
            if count >= 2:
                break
    if count < 2:
        ans = d
        break

print(ans)

Submission status: Time Limit Exceeded

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


ans = 0
for i in range(n):
    init = a_list[:]
    init.pop(i)
    gcd = gcd_list(init)
    if ans < gcd:
        ans = gcd

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 1

for i in range(N):
    flag = True
    if i == 0:
        a = As[1]
    else:
        a = As[0]
    for j in range(N):
        if j != i:
            a = fractions.gcd(a, As[j])
            if a <= ans:
                flag = False
                break
    if flag:
        ans = a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

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

ans = 1
for i in range(N):
    tmp = A.copy()
    tmp.pop(i)
    ag = int(functools.reduce(fractions.gcd, tmp))

    if ag > ans:
        ans = ag

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

max_g = As[1]
for i in range(2, N):
    max_g = gcd(As[i], max_g)

for i in range(1, N):
    g = As[0]
    for j in range(1, N):
        if j == i:
            continue
        g = gcd(As[j], g)
    max_g = max(max_g, g)

print(max_g)

Submission status: Time Limit Exceeded

Solution code:

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

    divisors.sort()
    return divisors


n = int(input())
a = list(map(int, input().split()))
divs = dict()
c = 1
for x in a:
    d = make_divisors(x)
    for y in d:
        if y in divs:
            if divs[y] >= c - 2:
                divs[y] += 1
        else:
            if c <= 2:
                divs[y] = 1
    c += 1
la = len(a)
maxdiv = 1
for k, v in divs.items():
    if v >= la - 1:
        maxdiv = max(maxdiv, k)
print(maxdiv)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
g=[]
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
B=A[:]
for i in range(N):
    del B[i]
    g.append(gcd_list(B))
    B=A[:]
print(max(g))

Submission status: Time Limit Exceeded

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

import copy
B = copy.copy(A)

import fractions
from functools import reduce

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

for i in range(N):
	del A[i]
	S[i] = gcd_list(A)
	A = copy.copy(B)
print(max(S))

Submission status: Time Limit Exceeded

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
pre_a = -1

for i in range(n):
    if pre_a != a[i]:
        values = a[:i] + a[i+1:]
        res = functools.reduce(gcd, values)
        ans = max(ans, res)
    pre_a = a[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

def ngcd(nums):
    d = 0
    for num in nums:
        d = gcd(d, num)
    return d

max = 1

for comb in itertools.combinations(a, n-1):
    ret = ngcd(comb)
    if ret > max:
        max = ret

print(max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(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)
    return divisors

candidate1 = []
candidate = {}
for i in range(N):
    if i == 0:
        candidate1 = make_divisors(A[i])
    elif i == 1:
        candidate2 = make_divisors(A[i])
        prev = -1
        for c in sorted(candidate1 + candidate2):
            if c != prev and prev != -1 and candidate[prev]['atari'] < 2:
                candidate[prev]['hazure'] += 1
            if c not in candidate:
                candidate[c] = {
                    'atari': 1,
                    'hazure': 0
                }
            else:
                candidate[c]['atari'] += 1
            prev = c
        if candidate[prev]['atari'] < 2:
            candidate[prev]['hazure'] += 1            
    else:
        delete_key = []
        for c in candidate.keys():
            if A[i] % c == 0:
                candidate[c]['atari'] += 1
            else:
                if candidate[c]['hazure'] > 0:
                    delete_key.append(c)
                else:
                    candidate[c]['hazure'] += 1
        for d in delete_key:
            del candidate[d]
print(max(candidate.keys()))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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


import fractions
from functools import reduce

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


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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy 
from functools import reduce

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

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

if __name__ == '__main__':
	N=int(input())
	A=list(map(int,input().split()))

	ans=0
	for i in range(N):
		l=copy.deepcopy(A)
		l.pop(int(i))
		tmp_gcd=gcd_list(l)	
		if(tmp_gcd > ans):
			ans= tmp_gcd
	print(ans)

Submission status: Time Limit Exceeded

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

def gcdList(numbers):
    return reduce(gcd, numbers)
  
n = int(input())
a = list(map(int,input().split()))

max = 0

for i in range(n):
  l = copy.deepcopy(a)
  l.pop(i)
  v = gcdList(l)
  if v > max:
    max = v
    
print(max)

Submission status: Time Limit Exceeded

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()]
gmax=0
for i in range(N):
  gcd=A[0] if i!=0 else A[1]
  for j in range(N):
    if i==j:continue
    if gcd==1:break
    gcd=gcdf(gcd,A[j])
  gmax=max((gmax,gcd))
print(gmax)

Submission status: Time Limit Exceeded

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


if N == 2:
    print(max(A[0], A[1]))
else:
    m = min(A)

    ans = -1
    for i in range(1, m+1):
        count = 0
        for n in range(N):
            if count > 1:
                break
            if A[n] % i != 0:
                count += 1
        if count <= 1 and i > ans:
            ans = i

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
res = 1
for i in range(max(a), 1, -1):
  count = 0
  for value in a:
    if value%i == 0 :
      count += 1
  if count >= (n-1) :
    res = i
    break
print(str(res))

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

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


from functools import lru_cache
import sys
if n == 2:
    print(max(a))
    sys.exit()


@lru_cache(maxsize=100000)
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def gcd_list(li):
    if len(li) == 1:
        return li[0]
    g = gcd(li[0], li[1])
    for i in range(2, len(li)):
        g = gcd(g, li[i])
    return g


def gcd_list_2(li):
    g = gcd(li[0], li[1])
    if g == 1:
        return max(gcd_list([li[0]] + li[2:]), gcd_list(li[1:]))
    for i in range(2, n):
        if gcd(g, li[i]) == 1:
            return max(gcd_list(li[:j] + li[j + 1:]) for j in range(i))
        else:
            g = gcd(g, li[i])
    return g


def max_gcd(a):
    g = gcd_list(a)
    a = [a[i]//g for i in range(n)]
    m = gcd_list_2(a)
    print(g * m)


max_gcd(a)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=a
c=[0]*n
ans=a[0]
def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z
for i in range(n):
    for j in range(n):
        if j==i:
            if j==0:
                ans=a[1]
            else:
                pass
        else:
            #print(j)
            ans=gcd(ans,a[j])
   # a[i]=b[i]
        c[i]=ans
    ans=a[0]
#print(c)
print(max(c))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
max=max(A)
for i in range(N):
    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: Time Limit Exceeded

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

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

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

temp = gcd_list(*A)
AA = list(A // temp)

temp2 = 0
for i in range(N):
    a = copy.copy(AA)
    a.pop(i)
    kouyaku = gcd_list(*a)
    temp2 = max(temp2, kouyaku)

print(temp * temp2)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce


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


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


n = int(input())
a = list(int(n) for n in input().split())

# print(gcd_list(a))

max = 0

for i in range(n):
    j = a.pop(0)
#    print(j)
#    print(a)
    if max < gcd_list(a):
        max = gcd_list(a)
#    print(gcd_list(a))
    a.append(j)
#    print(a)

print(max)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
 
N = int(input())
A = list(map(int, input().split()))
 
ans = 0
 
for i in range(N):
    tmp = A[:i] + A[i + 1:]
    g = 0
    for j in range(N - 1):
        g = gcd(tmp[j], g)
    ans = max(g, ans)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
    
N = int(input())
A = list(map(int,input().split()))

max_cd = -1
for i in range(N):
    tmp_list = A[0:i]
    tmp_list.extend(A[i+1:N])
    max_cd = max(gcd_list(tmp_list),max_cd)

print(max_cd)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = [int(n) for n in input().split()]
enh = [1 for _ in range(N)]
maxn = 1

dev = 2
while True:
    cnt = [0 for _ in range(N)]

    for i in range(N):
        while A[i] % dev == 0:
            A[i] /= dev
            cnt[i] += 1

    arg = np.argsort(np.array(cnt))
    maxn *= dev ** cnt[arg[0]]
    enh[arg[0]] *= dev ** (cnt[arg[1]] - cnt[arg[0]])

    if dev == 2:
        dev = 3
    elif dev == 3:
        dev = 5
    else:
        while dev % 2 == 0 or dev % 3 == 0 or dev % 5 == 0:
            dev += 1

    if sum(A) == N:
        break

print(maxn * max(enh))

Submission status: Time Limit Exceeded

Solution code:
import sys
def gcd(num_list,a,N):
  for i in range(min(num_list),a,-1):
    D = len([0 for o in num_list if o%i == 0])
    if D == N:
      return i
    elif D == N-1:
      return i
  return 1

def gcd2(num_list,a):
  for i in range(min(num_list),a,-1):
    if sum([o%i for o in num_list]) == 0:
      return i
  return 1

N = int(sys.stdin.readline())
A = list(map(int,sys.stdin.readline().split()))
ans1 = gcd(A,1,N)
temp = min(A)
A.remove(min(A))
ans2 = gcd2(A,temp)
print(max(ans1,ans2))

Submission status: Time Limit Exceeded

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 = 0

for i in range(n):
    b = a[:]
    b[i] = b[i-1]
    ans = max(ans, list_gcd(b))

print(ans)

Submission status: Time Limit Exceeded

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):
	tmp = A.copy()
	tmp.pop(i)
	gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd

print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	B = copy.copy(A)
	del B[i]
	tmp = B[0]
	for j in range(1, N - 1):
		tmp = fractions.gcd(tmp, B[j])
	ans = max(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

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 >= N-1:
            ans = div_list[d]
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
A = list(map(int, input().split()))
gcd_max = 0
for i in range(N):
    a_temp = A[:i]
    a_temp.extend(A[i + 1:])
    gcd_temp = a_temp[0]
    for a in a_temp:
        gcd_temp = fractions.gcd(gcd_temp, a)
        if gcd_temp <= gcd_max:
            break
    else:
        gcd_max = gcd_temp
print(gcd_max)

Submission status: Time Limit Exceeded

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

m = max(a)

for i in reversed(range(1,m+1)):
    torf = 2
    for j in a:
        if j % i != 0:
            torf -= 1

        if torf <= 0:
            break

    if torf <= 0:
        torf = 2
        continue
    else :
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
import functools
n = int(input())
a_list = list(map(int,input().split()))

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

res = []
tmp = []
for _ in range(n):
    e = a_list.pop(0)
    if e in tmp:
        continue
    res.append(functools.reduce(gcd, a_list))
    a_list.append(e)
    tmp.append(e)

print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import math

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
    
def list_gcd(x):
    if len(x) == 1:
        return x[0]
    next_list = []
    for i in range(int(len(x)/2)):
        next_list.append(gcd(x[2*i],x[2*i+1]))
    if len(x)%2 == 1:
        next_list.append(x[-1])
    
    return list_gcd(next_list)

out = 0
for i in range(len(A)):
    l = A[:i] + A[i+1:]
    this_gcd = list_gcd(l)
    if this_gcd > out:
        out = this_gcd
        
print(out)

Submission status: Time Limit Exceeded

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):
        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: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

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

min_gcd = 1
if min_gcd < gcd_right[1]:
    min_gcd = gcd_right[1]
if min_gcd < gcd_left[N-2]:
    min_gcd = gcd_left[N-2]
for i in range(0,N-2):
    tmp = fractions.gcd(gcd_left[i],gcd_right[i+2])
    if tmp > min_gcd:
        min_gcd = tmp
        
print(min_gcd)

Submission status: Time Limit Exceeded

Solution code:
# a>b
dic = {}

def gcd(a, b):
    key = (a, b)
    if key in dic:
        return dic[key]
    ans = 0
    if b == 0:
        ans = a
    else:
        ans = gcd(b, a%b)
    dic[key] = ans
    return ans

def gcd_arr(arr):
    if len(arr)==1:
        return arr[0]
    i = len(arr)//2
    l, r = (gcd_arr(arr[:i]), gcd_arr(arr[i:]))
    return gcd(l, r) if l>r else gcd(r, l)

N = int(input())
As = [int(s) for s in input().split()]
ans = 1

for i in range(N):
    curr = None
    arr = [As[j] for j in range(N) if i!=j]
    ans = max(ans, gcd_arr(arr))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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
    
    
kosuu = int(input())
nums = list(map(int,input().split()))

temp_arr=[]
for temp in nums:
    temp_arr.extend(make_divisors(temp))
    
temp_arr.sort(reverse=True)
for temp in temp_arr:
    suuzi = temp_arr.count(temp)
    if suuzi == kosuu -1 or suuzi == kosuu:
        print(temp)
        break

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().rstrip().split(' ')))
    cache = {}
    def gcd_bw_except(left, right, skip):
        if left in cache:
            if right in cache[left]:
                if skip in cache[left][right]:
                    return cache[left][right][skip]
        if right - left == 1:
            if left == skip:
                safe_put(cache, left, right, skip, None)
                return None
            else:
                safe_put(cache, left, right, skip, a[left])
                return a[left]
        else:
            v = gcd(gcd_bw_except(left, (right - left)//2 + left , skip), gcd_bw_except((right - left)//2 + left, right, skip))
            safe_put(cache, left, right, skip, v)
            return v
    max_gcd = 0
    for i in range(n):
        prev = gcd_bw_except(0, n, i)
        if max_gcd < prev:
            max_gcd = prev
    print(max_gcd)


def safe_put(d, k1, k2, k3, v):
    if k1 in d:
        if k2 in d[k1]:
            d[k1][k2][k3] = v
        else:
            d[k1][k2] = {k3: v}
    else:
        d[k1] = {k2: {k3: v}}

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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

def readInts():
  return [int(s) for s in input().split(" ")]

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

def gcds(A):
  ret = A[0]
  for n in A[1:]:
    ret = gcd(ret, n)
  return ret

def main():
  N = readInts()[0]
  A = readInts()

  m = 1
  for i in range(N):
    m = max(m, gcds(A[0:i] + A[i+1:]))
  print(m)

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

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

ans = []

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

def gcd_list(numbers):
    while len(numbers) > 2:
        x1 = numbers.pop()
        y1 = numbers.pop()
        numbers.append(gcd(x1, y1))
    return gcd(numbers[0], numbers[1])

if n == 2:
    print(max(a))
else:
    for i in range(n):
        c = a.copy()
        c.remove(a[i])
        ans.append(gcd_list(c))

    print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from fractions import gcd
from functools import reduce

input = stdin.readline

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

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

gcd_max = gcd_list(A)

for i in range(N):
    A_test = A[:i] + A[i+1:]
    gcd_test = gcd_list(A_test)
    if gcd_max <= gcd_test:
        gcd_max = gcd_test

print(gcd_max)

Submission status: Time Limit Exceeded

Solution code:
def gcd(num_list,a,N):
  for i in range(min(num_list),a,-1):
    D = len([0 for o in num_list if o%i == 0])
    if D == N:
      return i
    elif D == N-1:
      return i
  return 1

def gcd2(num_list,a):
  for i in range(min(num_list),a,-1):
    if sum([o%i for o in num_list]) == 0:
      return i
  return 1

N = int(input())
A = list(map(int,input().split()))
ans1 = gcd(A,1,N)
temp = min(A)
A.remove(min(A))
ans2 = gcd2(A,temp)
print(max(ans1,ans2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
m=0
for i in range(max(A),0,-1):
    count=0
    for a in A:
        if a%i==0:count+=1
        if count>=n-1:
            print(i)
            exit()

Submission status: Time Limit Exceeded

Solution code:
memo = {}

def gcd(a, b):
    if (a, b) in memo.keys():
        return memo[(a, b)]
    if b == 0:
        return a
    g = gcd(b, a % b)
    memo[(a, b)] = g
    return g

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i, a in enumerate(a_list):
        if i == 0 or i == exclude:
            continue
        g_new = gcd(g, a)
        if (g, a) not in memo:
            memo[(g, a)] = g_new
        g = g_new
        if g <= max_g:
            break
    if g > max_g:
        max_g = g
print(max_g)

Submission status: Time Limit Exceeded

Solution code:
def gcd(aa, bb):
	while bb:
		aa, bb = bb, aa % bb
	return aa

n = int(input())

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

a = sorted(a)
ans = 0
for i in range(n):
    flag = False
    j = 0
    if i == 0:
        tmp = a[1]
    else:
        tmp = a[0]
    while not flag and j != n:
        if j != i:
            tmp = gcd(tmp, a[j])
        if tmp == 1:
            flag = True
        j += 1
    if tmp > ans:
        ans = tmp
    if ans >= a[0]:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

def divisors():
    for i in range(B[0], 0, -1):
        if any(map(lambda n: n%i==0, A)):
            yield i

ans = 1
divs = divisors()
for d in divs:
    count = 0
    for a in A:
        if a % d != 0:
            count += 1
            if count >= 2:
                break
    if count < 2:
        ans = d
        break

print(ans)

Submission status: Time Limit Exceeded

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

    # divisors.sort()
    return divisors


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

divisor_num = {}
for number in numbers:
    divisors = make_divisors(number)

    for divisor in divisors:
        if divisor in divisor_num:
            divisor_num[divisor] += 1
        else:
            divisor_num[divisor] = 1

res = 1
for k, v in divisor_num.items():
    if v == n or v == n-1:
        res = max(res, k)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions
import copy

N = int(input())
a_list = list(map(int, input().split()))
gcd_list = []
for i in range(N):
    copied = copy.copy(a_list)
    copied.pop(i)
    gcd = functools.reduce(fractions.gcd, copied)
    gcd_list.append(gcd)

print(max(gcd_list))

Submission status: Time Limit Exceeded

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


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


ans = -1
for i in range(N):
    flg = 0
    tmp = A[:i] + A[i+1:]
    Gcd = tmp[0]
    for j in range(N-2):
        g = gcd(tmp[j], tmp[j+1])
        Gcd = gcd(Gcd, g)
        if Gcd < ans:
            flg = 1
            break
    if flg:
        continue
    ans = max(ans, Gcd)

print(ans)