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:
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n<-16:
    a.sort()
    ns=int(n/8)
    a1=a[0:ns]
    a2=a[ns:ns*2]
    a3=a[ns*2:ns*3]
    a4=a[ns*3:n]
    gcdv=0
    gcd1=gcdf(a1,len(a1),gcdv)
    gcd2=gcdf(a2,len(a2),gcdv)
    gcd3=gcdf(a3,len(a3),gcdv)
    gcd4=gcdf(a4,len(a4),gcdv)
    for i in range(ns):
        acpy=list(a1)
        acpy.append(gcd2)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    for i in range(ns):
        acpy=list(a2)
        acpy.append(gcd1)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    for i in range(ns):
        acpy=list(a3)
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd4)
        del acpy[i]
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    for i in range(ns):
        acpy=list(a4)
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd3)
        del acpy[i]
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
    
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Time Limit Exceeded

Solution code:
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
    a.sort(reverse=True)
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Time Limit Exceeded

Solution code:
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Time Limit Exceeded

Solution code:
def gcdf(a,n):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
#            ra=a[i]%a0
#            print(i,a[i],a0,ramin)
            if ramin>a[i] and a[i]!=0:
                ramin=a[i]
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
#        del acpy[i]
        gcdx=gcdf(acpy,n-1)
#        gcdx=gcdf(a,n-1)
#        gcdx=gcd(acpy)
#        gcdx=functools.reduce(gcd,acpy)
#        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
        aa=a[0]
        del a[0]
        a.append(aa)
    print(gcdv)

Submission status: Time Limit Exceeded

Solution code:
def gcdf(a,n):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
#            ra=a[i]%a0
#            print(i,a[i],a0,ramin)
            if ramin>a[i] and a[i]!=0:
                ramin=a[i]
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1)
#        gcdx=gcd(acpy)
#        gcdx=functools.reduce(gcd,acpy)
#        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Time Limit Exceeded

Solution code:
def gcdf(a,n):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
#            ra=a[i]%a0
#            print(i,a[i],a0,ramin)
            if ramin>a[i] and a[i]!=0:
                ramin=a[i]
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
#    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1)
#        gcdx=gcd(acpy)
#        gcdx=functools.reduce(gcd,acpy)
#        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(n):
  g = l[0] if i > 0 else l[1]
  for j in range(1,n):
    if j != i:
      g = gcd(g, l[j])
  ans = max(ans, g)

print(ans)

Submission status: Time Limit Exceeded

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


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

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

GCD = []
for i in range(n):
    A2 = A[:i] + A[i + 1:]
    g = gcd(A2[0], A2[1])
    for j in range(2, n - 1):
        g = gcd(g, A2[j])
        if g == 1:
            break
    GCD.append(g)

print(max(GCD))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import random
import time

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

if N == 1:
    print(A[0])
elif N == 2:
    print(max(A))
else:
    d1 = gcd(A[0], A[1])
    for i in range(2, N):
        d1 = gcd(d1, A[i])

    xs = [x // d1 for x in A]
    _t = time.time()
    max_d = 0
    while time.time() - _t < 1.8:
        i = random.randint(0, N - 1)
        ys = xs[:i] + xs[i + 1:]
        d2 = gcd(ys[0], ys[1])
        for j in range(2, len(ys)):
            d2 = gcd(d2, ys[j])
        max_d = max(max_d, d2)
    print(d1 * max_d)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
from collections import deque


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

ans = 1
a = A.pop()
for i in range(N):
  ans = max(ans, reduce(gcd, A))
  A.appendleft(a)
  a = A.pop()

print(ans)

Submission status: Time Limit Exceeded

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

def gcd(*numbers):
    return abs(reduce(fractions.gcd, numbers))
ans = 0
for i in range(N):
    temp = A[:i] + A[i+1:]
    ans = max(ans, gcd(*temp))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x 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)

    divisors.sort()
    return divisors
div = []
for i in A:
    div += make_divisors(i)
from collections import Counter
c = Counter(div)
ans = 0
for i in c.keys():
    if c[i] >= N - 1:
        ans = max(ans, i)
print(ans)

Submission status: Time Limit Exceeded

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

def gcd(*numbers):
    return abs(reduce(fractions.gcd, numbers))
ans = 0
for i in range(N):
    temp = A[:i] + A[i+1:]
    ans = max(ans, gcd(*temp))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Nの最小値を Max にして、全部の数字が割り切れるかどうかを探索する。ってのはどうだろう
# どんなに頑張ってもO(N^2)だからあとは下から攻めるか上から攻めるかみたいなところではあるが…
N = int(input())
An = [a for a in map(int, input().split())]
An.sort()
Max = An[0]
ans = 0
for i in range(1, Max+1):
  cnt = 0
  for A in An:
    if A%i != 0:
      cnt += 1
  if cnt <= 1:
    ans = i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Nの最小値を Max にして、全部の数字が割り切れるかどうかを探索する。ってのはどうだろう
# どんなに頑張ってもO(N^2)だからあとは下から攻めるか上から攻めるかみたいなところではあるが…
N = int(input())
An = [a for a in map(int, input().split())]
An.sort()
Max = An[0]
ans = 0
for i in range(1,Max + 1):
  cnt = 0
  for A in An:
    if A%i != 0:
      cnt += 1
  if cnt <= 1:
    ans = i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import os, sys, re, math, fractions

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

def common_gcd(ex_idx):
    ret = 0
    for i in range(N):
        if i != ex_idx:
            if ret == 0:
                ret = A[i]
            else:
                ret = fractions.gcd(ret, A[i])
    return ret

ret = 1
for j in range(N):
    ret = max(ret, common_gcd(j))

print(ret)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in reversed(range(0, max(a) + 1)):
	cnt = 0
	cnt_not = 0
	for j in a:
		if j % i == 0:
			cnt += 1
		else:
			cnt_not += 1
			if cnt_not > 1:
				break
	if cnt >= (len(a) - 1):
		print(i)
		break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
for i in reversed(range(0, max(a) + 1)):
	cnt = 0
	for j in a:
		if j % i == 0:
			cnt += 1
	if cnt >= (len(a) - 1):
		print(i)
		break

Submission status: Time Limit Exceeded

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

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

l_ans = [0] * n
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[j])
    l_ans[i] = g
r_ans = [0] * n
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[n-1-j])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)

Submission status: Time Limit Exceeded

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

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

l_ans = []
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[j])
    l_ans.append(g)
r_ans = []
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[n-1-j])
    r_ans.append(g)
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
v = list(map(int,input().split()))
v = deque(v)

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

ans = 1
for i in range(n):
    v1 = v.popleft()
    g = 0
    for j in range(n-1):
        g = gcd(g, v[j])
    v.append(v1)
    ans = max(ans,g)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from fractions import gcd
from functools import reduce
n = int(input())
v = list(map(int,input().split()))
v = deque(v)

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

ans = 1
for i in range(n):
    v1 = v.popleft()
    g = gcd_list(v)
    v.append(v1)
    ans = max(ans,g)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from fractions import gcd
from functools import reduce
n = int(input())
v = list(map(int,input().split()))
v = deque(v)

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

ans = 1
for i in range(n):
    v1 = v.popleft()
    g = gcd_list(v)
    v.append(v1)
    ans = max(ans,g)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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

def gcd_list(numbers):
    return reduce(gcd, numbers)
m = list()
for i in range(n):
    m.append(gcd_list(As[:i]+As[i+1:]))
print(max(m))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(gcd,lista)
ans = []
ans.append(gcdlist(A[1:]))
ans.append(gcdlist(A[:-1]))
for i in range(1,N-1):
    ans.append(gcd(gcdlist(A[:i]),gcdlist(A[i+1:])))
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
#ABC125_C
import fractions
from functools import reduce
 
def gcd(nums):
    return reduce(fractions.gcd,nums)
 
N=int(input())
A=list(map(int,input().split()))
ans=1
       
for i in range(N):
    temp=A.copy()
    temp.remove(temp[i])
    if gcd(temp) > ans:
        ans=gcd(temp)
print(ans)

Submission status: Time Limit Exceeded

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

import fractions

def gcdoflist(l):
    n=len(l)
    if n==1:
        return l[0]
    else:
        ans=l[0]
        for i in range(1,n):
            ans=fractions.gcd(ans,l[i])
        return ans
m_list=[]
#端点の場合
#右端
m_list.append(gcdoflist(al[0:n-1]))

#左端
m_list.append(gcdoflist(al[1:n]))
ans=max(m_list)
for i in range(1,n-1):
    left=al[0:i]
    right=al[i+1:n]
    temp=fractions.gcd(gcdoflist(left),gcdoflist(right))
    if temp>ans:
        ans=temp
print(ans)

Submission status: Time Limit Exceeded

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

import fractions

def gcdoflist(l):
    n=len(l)
    if n==1:
        return l[0]
    else:
        ans=l[0]
        for i in range(1,n):
            ans=fractions.gcd(ans,l[i])
        return ans
m_list=[]
#端点の場合
#右端
m_list.append(gcdoflist(al[0:n-1]))

#左端
m_list.append(gcdoflist(al[1:n]))

for i in range(1,n-1):
    left=al[0:i]
    right=al[i+1:n]
    m_list.append(fractions.gcd(gcdoflist(left),gcdoflist(right)))
print(max(m_list))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

import numpy as np
import fractions
from functools import reduce

from copy import deepcopy


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

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

    bools = np.ones(N, dtype=bool)

    ans = 0
    vals = []
    for i in range(N):
        A_cop = deepcopy(A)
        bl_cop = deepcopy(bools)

        fal = [i]
        bl_cop[fal] = False

        vals.append(gcd_list(A_cop[bl_cop]))

    print(max(vals))

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

import numpy as np
import fractions
from functools import reduce

from copy import deepcopy


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

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

    bools = np.ones(N, dtype=bool)

    gcd_val = 0
    ans = 0
    for i in range(N):
        A_cop = deepcopy(A)
        bl_cop = deepcopy(bools)

        fal = [i]
        bl_cop[fal] = False

        gcd_val = gcd_list(A_cop[bl_cop])

        if ans == 0 or ans < gcd_val:
            ans = gcd_val

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

import numpy as np
import fractions
from functools import reduce

from copy import deepcopy

import warnings

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


def main():
    warnings.simplefilter('ignore')

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

    bools = np.ones(N, dtype=bool)

    gcd_val = 0
    ans = 0
    for i in range(N):
        A_cop = deepcopy(A)
        bl_cop = deepcopy(bools)

        fal = [i]
        bl_cop[fal] = False

        gcd_val = gcd_list(A_cop[bl_cop])

        if ans == 0 or ans < gcd_val:
            ans = gcd_val

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
#ABC125_C
import fractions
from functools import reduce

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

N=int(input())
A=list(map(int,input().split()))
ans=1
       
for i in range(N):
       temp=A.copy()
       temp.pop(i)
       if gcd(temp) > ans:
           ans=gcd(temp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split()))
max_gcd = 1

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

def gcd_list(l):
    max_gcd = l[0]
    for el in l[1:]:
        max_gcd = gcd(max_gcd,el)
    return max_gcd


for i in range(N):
    max_gcd = max(max_gcd, gcd_list(l[:i]+l[i+1:]))

print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i in range(N):
  if i < N-1:
    a = A[i]
    A[i] = A[i+1]
  else:
    A[i] = A[0]
  ans = max(ans, reduce(gcd,A))
  A[i] = a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i in range(N):
  L = A[:i]
  R = A[i+1:]
  ans = max(ans, reduce(gcd,L+R))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
n = int(input())
L = list(map(int,input().split()))
def GCD1(a,b):
    return gcd(a,b)
def GCD2(L):
    return reduce(GCD1,L)

liL = [0]*(n)
liR = [0]*(n)
for i in range(1,n+1):
    if len(L[:i-1]) == 0:
        liL[i-1] = 0
        liR[i-1] = (GCD2(L[i:]))
    elif len(L[i:]) == 0:
        liR[i-1] = 0
        liL[i-1] = (GCD2(L[:i-1]))
    else:
        liL[i-1] = (GCD2(L[:i-1]))
        liR[i-1] = (GCD2(L[i:]))
    #print(L[:i-1],L[i:])
    #print(liL,liR)
#print(liL,liR)
ans = 0
for a,b in zip(liL,liR):
    ans = max(ans,GCD1(a,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()]
ans = 0

for i in range(n):
    m = functools.reduce(fractions.gcd, a[:i] + a[i+1:])
    ans = max(ans, m)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

ans = 0
for i in range(N):
    pop = A.pop(0)
    ans = max(ans, gcd(*A))
    A.append(pop)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
import fractions
from functools import reduce

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

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

ans = 0
for i in range(N):
    tmp = copy.copy(A)
    pop = A.pop(0)
    ans = max(ans, gcd(*A))
    A.append(pop)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
import fractions
from functools import reduce

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

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

ans = 0
for i in range(N):
    tmp = copy.copy(A)
    tmp.pop(i)
    ans = max(ans, gcd(*tmp))

print(ans)

Submission status: Time Limit Exceeded

Solution code:

from fractions import gcd
from functools import reduce

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

ans = 0
for i in range(N):
 B = A[:]
 B.pop(i)
 ans = max(ans, reduce(gcd, B))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions

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


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


ans = 0
for i in range(N):
    B = A[:i]+A[i+1:]
    ans = max(ans, gcd(*B))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
A = str(input())
A = A.split()
A_list = []
for i in range(N):
    A_list.append(int(A[i]))

max_count = 0
for i in range(N):   
    A_change = []
    for j in range(N):
        A_change.append(int(A_list[j]))
    A_change.pop(i)
    
    ans = A_change[0]
    for i in range(1, N-1):
        ans = fractions.gcd(ans, A_change[i])
    val = ans
    
    if val > max_count:
        max_count = val

print(max_count)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
 
def gcd_list(numbers):
    return reduce(gcd, numbers)
 
N = int(input())
A = [i for i in map(int, input().split())]
 
gcd_max = 0
for i in range(N):
  gcd_temp = gcd_list([A[l] for l in range(N) if l != i])
  if gcd_max < gcd_temp:
    gcd_max = gcd_temp
    
print(gcd_max)

Submission status: Time Limit Exceeded

Solution code:
import math
#約数を列挙する関数
def return_child(num,result):
  for i in range(1, int(math.sqrt(num))+1, 1):
    if num % i == 0:
      result.append(i)
      if i != num//i:
        result.append(num // i)    
  return result

N = int(input())

nums = list(map(int, input().split(' ')))
nums.sort()

tmp = []
x = return_child(nums[0],tmp)
tmp = []
second_possible = return_child(nums[1],tmp)

possible = []
for i in range(len(x)):
  possible.append((x[i], 1))
  
for i in range(1,N,1):
  result = []
  for j in range(len(possible)):
    if nums[i] % possible[j][0] == 0:
      continue
    else:
      if possible[j][1] == 0:
        possible[j] = (possible[j][0], -1)
      elif possible[j][1] == 1:
        possible[j] = (possible[j][0], 0)
          
  possible = [tup for tup in possible if tup[1] >= 0]
    
for i in range(2,N,1):
  result = []
  remove_list = []
  for j in range(len(second_possible)):
    if nums[i] % second_possible[j] == 0:
      continue
    else:
      remove_list.append(second_possible[j])
      
  second_possible = [i for i in second_possible if i not in remove_list]
    
default = []
challenge = []

for i in range(len(possible)):
  if possible[i][1] == 0:
    challenge.append(possible[i][0])
  elif possible[i][0] == 1:
    default.append(possible[i][0])

challenge.extend(second_possible)

default.sort()
challenge.sort()

if challenge == []:
  print(default[-1])
else:
  print(challenge[-1])

Submission status: Time Limit Exceeded

Solution code:
import math
#約数を列挙する関数
def return_child(num,result):
  for i in range(1, int(math.sqrt(num))+1, 1):
    if num % i == 0:
      result.append(i)
      if i != num//i:
        result.append(num // i)    
  return result

N = int(input())

nums = list(map(int, input().split(' ')))
nums.sort()

tmp = []
x = return_child(nums[0],tmp)
tmp = []
second_possible = return_child(nums[1],tmp)

possible = []
for i in range(len(x)):
  possible.append((x[i], 1))
  
for i in range(1,N,1):
  result = []
  for j in range(len(possible)):
    if nums[i] % possible[j][0] == 0:
      continue
    else:
      if possible[j][1] == 0:
        possible[j] = (possible[j][0], -1)
      elif possible[j][1] == 1:
        possible[j] = (possible[j][0], 0)
          
  possible = [tup for tup in possible if tup[1] >= 0]
    
for i in range(2,N,1):
  result = []
  remove_list = []
  for j in range(len(second_possible)):
    if nums[i] % second_possible[j] == 0:
      continue
    else:
      remove_list.append(second_possible[j])
      
  second_possible = [i for i in second_possible if i not in remove_list]
    
default = []
challenge = []

for i in range(len(possible)):
  if possible[i][1] == 0:
    challenge.append(possible[i][0])
  elif possible[i][0] == 1:
    default.append(possible[i][0])
    
for i in range(len(second_possible)):
  challenge.append(second_possible[i])

default.sort()
challenge.sort()

if challenge == []:
  print(default[-1])
else:
  print(challenge[-1])

Submission status: Time Limit Exceeded

Solution code:
import math
#約数を列挙する関数
def return_child(num,result):
  for i in range(1, int(math.sqrt(num))+1, 1):
    if num % i == 0:
      result.append(i)
      if i != num//i:
        result.append(num // i)    
  return result

N = int(input())

nums = list(map(int, input().split(' ')))
nums.sort()

tmp = []
x = return_child(nums[0],tmp)
tmp = []
y = return_child(nums[1],tmp)

possible = []
for i in range(len(x)):
  possible.append((x[i], 1))

second_possible = []
for i in range(len(y)):
  second_possible.append(y[i])

for i in range(1,N,1):
  result = []
  for j in range(len(possible)):
    if nums[i] % possible[j][0] == 0:
      continue
    else:
      if possible[j][1] == 0:
        possible[j] = (possible[j][0], -1)
      elif possible[j][1] == 1:
        possible[j] = (possible[j][0], 0)
          
  possible = [tup for tup in possible if tup[1] >= 0]
    
for i in range(2,N,1):
  result = []
  remove_list = []
  for j in range(len(second_possible)):
    if nums[i] % second_possible[j] == 0:
      continue
    else:
      remove_list.append(second_possible[j])
      
  second_possible = [i for i in second_possible if i not in remove_list]
    
default = []
challenge = []

for i in range(len(possible)):
  if possible[i][1] == 0:
    challenge.append(possible[i][0])
  elif possible[i][0] == 1:
    default.append(possible[i][0])
    
for i in range(len(second_possible)):
  challenge.append(second_possible[i])

default.sort()
challenge.sort()

if challenge == []:
  print(default[-1])
else:
  print(challenge[-1])

Submission status: Time Limit Exceeded

Solution code:
import math
#約数を列挙する関数
def return_child(num,result):
  for i in range(1, int(math.sqrt(num))+1, 1):
    if num % i == 0:
      result.append(i)
      if i != num//i:
        result.append(num // i)    
  return result

N = int(input())

nums = list(map(int, input().split(' ')))
nums.sort()

tmp = []
x = return_child(nums[0],tmp)
tmp = []
y = return_child(nums[1],tmp)

possible = []
for i in range(len(x)):
  possible.append((x[i], 1))

second_possible = []
for i in range(len(y)):
  second_possible.append((y[i], 0))

for i in range(1,N,1):
  result = []
  for j in range(len(possible)):
    if nums[i] % possible[j][0] == 0:
      continue
    else:
      if possible[j][1] == 0:
        possible[j] = (possible[j][0], -1)
      elif possible[j][1] == 1:
        possible[j] = (possible[j][0], 0)
          
possible = [tup for tup in possible if tup[1] >= 0]
    

for i in range(2,N,1):
  result = []
  for j in range(len(second_possible)):
    if nums[i] % second_possible[j][0] == 0:
      continue
    else:
      if second_possible[j][1] == 0:
        second_possible[j] = (second_possible[j][0], -1)
      
second_possible = [tup for tup in second_possible if tup[1] >= 0]
    
default = []
challenge = []

for i in range(len(possible)):
  if possible[i][1] == 0:
    challenge.append(possible[i][0])
  elif possible[i][0] == 1:
    default.append(possible[i][0])
    
for i in range(len(second_possible)):
  challenge.append(second_possible[i][0])

default.sort()
challenge.sort()

if challenge == []:
  print(default[-1])
else:
  print(challenge[-1])

Submission status: Time Limit Exceeded

Solution code:
import math
#約数を列挙する関数
def return_child(num,result):
  for i in range(1, int(math.sqrt(num))+1, 1):
    if num % i == 0:
      result.append(i)
      if i != num//i:
        result.append(num // i)    
  return result

N = int(input())

nums = list(map(int, input().split(' ')))
nums.sort()

tmp = []
x = return_child(nums[0],tmp)
tmp = []
y = return_child(nums[1],tmp)

possible = []
for i in range(len(x)):
  possible.append((x[i], 1))

second_possible = []
for i in range(len(y)):
  second_possible.append((y[i], 0))

for i in range(1,N,1):
  result = []
  for j in range(len(possible)):
    if nums[i] % possible[j][0] == 0:
      continue
    else:
      if possible[j][1] == 0:
        possible[j] = (possible[j][0], -1)
      elif possible[j][1] == 1:
        possible[j] = (possible[j][0], 0)
          
  possible = [tup for tup in possible if tup[1] >= 0]
    

for i in range(2,N,1):
  result = []
  for j in range(len(second_possible)):
    if nums[i] % second_possible[j][0] == 0:
      continue
    else:
      if second_possible[j][1] == 0:
        second_possible[j] = (second_possible[j][0], -1)
      
  second_possible = [tup for tup in second_possible if tup[1] >= 0]
    
default = []
challenge = []

for i in range(len(possible)):
  if possible[i][1] == 0:
    challenge.append(possible[i][0])
  elif possible[i][0] == 1:
    default.append(possible[i][0])
    
for i in range(len(second_possible)):
  challenge.append(second_possible[i][0])

default.sort()
challenge.sort()

if challenge == []:
  print(default[-1])
else:
  print(challenge[-1])