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:
n = int(input())
a = list(map(int, input().split()))

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

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n):
        b = a[:i] + a[i + 1:]
        element = gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = gcd(element, b[j])
            ans = max(ans, element)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    tmp = x%y
    while not tmp == 0:
        x = y
        y = tmp
        tmp = x%y
    return y
N = int(input())
A = list(map(int,input().split()))

gcd_max = 0
for i in range(N):
    tmp = A[0]
    if i == 0:
        tmp = A[1]
    for j in range(N):
        if not j == i:
            tmp = gcd(tmp,A[j])
    if tmp > gcd_max:
        gcd_max = tmp
print(gcd_max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
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
divs = make_divisors(a[0]) #list

divsTF = [0]*len(divs)
for i in range(len(divs)):
    j = [1 if a[_] % divs[i] else 0 for _ in range(n) ]

    if sum(j) <= 1:
        divsTF[i] = 1

ans = 1
for i in range(len(divs)):
    if divsTF[i] == 1:
        ans = max(ans,divs[i])


divs2 = make_divisors(a[1]) #list

divsTF2 = [0]*len(divs2)
for i in range(len(divs2)):
    j = [1 if a[_] % divs2[i] else 0 for _ in range(n) ]

    if sum(j) <= 1:
        divsTF2[i] = 1

aans = 1
for i in range(len(divs2)):
    if divsTF2[i] == 1:
        aans = max(aans,divs2[i])
print(max(aans,ans))

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


candidate = {}
for i in range(N):
    if i == 0:
        candidate1 = make_divisors(A[i])
        for c in candidate1:
            candidate[c] = {
                'atari': 1,
                'hazure': 0,
            }
    elif i == 1:
        candidate2 = make_divisors(A[i])
        for c in candidate:
            if c not in candidate2:
                candidate[c]['hazure'] += 1
        for c in candidate2:
            if c not in candidate:
                candidate[c] = {
                    'atari': 1,
                    'hazure': 1
                }
            else:
                candidate[c]['atari'] += 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:
import numpy as np

def gcd(a, b):
    maxV = max(a, b)
    minV = min(a, b)
    if minV == 0:
        return maxV
    else:
        return gcd(minV, maxV%minV)

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

maxg = 0
if N == 2:
    print(max(Alist))
else:
    for i in range(0, N):
        tmp = np.array(Alist)
        g = 0
        if i != N - 1:
            tmp[i] = tmp[i + 1]
        else:
            tmp[i] = tmp[i - 1]
        for j in range(1, N):
            if j == 1:
                g = gcd(tmp[0], tmp[1])
            else:
                g = gcd(g, tmp[j])
        if maxg < g:
            maxg = g
    print(maxg)

Submission status: Time Limit Exceeded

Solution code:
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def gcd(x, y):  # 最大公約数
    m = max(x, y)
    n = min(x, y)
    while m % n != 0:
        w = m % n
        m = n
        n = w
    return n

def prob():
    d = Debug()
    d.off()
    N = getInt()
    A = getIntList()
    d.dmp((N),'N')
    d.dmp((A),'A')
    g = [0]*N
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            if g[i] == 0:
                g[i] = A[j]
            g[i] = gcd(g[i], A[j])
    d.dmp((g),'g')
    return max(g)

ans = prob()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from copy import copy
def gcd(a,b):
  if b==0:return a
  return gcd(b,a%b)
def sakana(numbers):
    return reduce(gcd, numbers)
n = int(input())
listA = list(map(int, input().split()))
listB = copy(listA)
listC = []
a = 0
for i in range(n):
    del listB[i]
    a = sakana(listB)
    listC.append(a)
    listB = copy(listA)
print(max(listC))

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions as math
from functools import reduce

input = sys.stdin.readline


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


def gcd2(index, a_list):
    nums = a_list[:]
    del nums[index]
    return gcd(nums)


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(max([gcd2(i, a_list) for i in range(n)]))


if __name__ == "__main__":
    main()

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 = []

for i in range(n):
    e = a_list.pop(0)
    res.append(functools.reduce(gcd, a_list))
    a_list.append(e)

print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy

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

def calc_gcd(list):
    ans = list[0]
    for i in range(1,n-1):
        ans = fractions.gcd(ans,list[i])
    return ans

#a = [1,2,3,4,5,6,7]

for j in range(n):
    b= copy.copy(a)
    b.pop(j)
    nlist.append(calc_gcd(b))

#print(nlist)
print(max(nlist))
#
# print(calc_gcd([16,100,4000]))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

def get_gcd(*alist):
    return reduce(fractions.gcd, alist)

max_gcd = 0
for i in range(N):
    A_=[]
    for j in range(N):
        if j != i:
            A_.append(A[j])
    gcd = get_gcd(*A_)
    if max_gcd < gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce
import copy

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

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

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

b = []
for i in range(n):
    #a_tmp = []
    a_tmp = copy.copy(a)
    a_tmp.pop(i)
    b.append(gcd(*a_tmp))
b.sort(reverse=True)
print(b[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [int(i) for i in input().split()]
def calc(a, b):
    r = a % b
    while(r != 0):
        a = b
        b = r
        r = a % b
    return b
answer = 0
for i in range(len(As)):
    As_copy = As.copy()
    res = As_copy.pop(i)
    if i == N-1:
        i = 0
    _ = As_copy.pop(i)
    for j in As_copy:
        if i == j:
            continue
        temp = calc(res, j)
        res = temp
    if res > answer:
        answer = res
print(answer)

Submission status: Time Limit Exceeded

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

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

glist = []
for i in range(N):
    a = deepcopy(A)
    a.pop(i)
    g = a[0]
    for j in range(N-1):
        g = gcd(g, a[j])
        if g == 1:
            break
    glist.append(g)

print(max(glist))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import fractions
from collections import deque
 
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A = deque(A)
 
res = []
tmp = 0 
 
for i in range(N):
    tmp = A.popleft()
    gcd_num = A[0]
    for j in range(1, N-1):
        gcd_num = fractions.gcd(gcd_num, A[j])
    res.append(gcd_num)
    A.append(tmp)

 
print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import copy
import fractions


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    gcd_list = []
    if n == 1:
        print(10**10 - 1)
    else:
        for i in range(len(a_list)):
            cp_list = copy.copy(a_list)
            del cp_list[i]
            gcd_tmp = cp_list.pop()
            for num in cp_list:
                gcd_tmp = fractions.gcd(gcd_tmp, num)
            gcd_list.append(gcd_tmp)
        print(max(gcd_list))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools
n=input()
n=int(n)
a=input().split()
a=[int(i) for i in a]
ncount=2
count=0
gll=list()
for i in range(n):
    s=a[i]
    del a[i]
    gcd = functools.reduce(fractions.gcd, a)
    gll.append(gcd)
    a.insert(i,s)
print(max(gll))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def mkt(a, b):
    while b:
        a, b = b, a % b
    return a
def gcd_list(numbers):
    return reduce(mkt, numbers)
n=int(input())
a=list(map(int,input().split()))
max=1
for i in range(n):
    q=gcd_list(a[:i]+a[i+1:])
    if q>max:
        max=q
print(max)

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

first = make_divisors(As[0])
second = make_divisors(As[1])
first_second = list(set(first) & set(second))
first_second.sort(reverse=True)
for d in range(len(first_second)):
    cnt = 0
    for i in range(N):
        if As[i] % (first_second[d]) == 0:
            cnt += 1
    if cnt >= N-1:
        ans_a = first_second[d]
        break
if N == 2:
    print(max(As))
else:
    third  = make_divisors(As[2])
    
    first_third = list(set(first) & set(third))
    first_third.sort(reverse=True)
    second_third = list(set(third) & set(second))
    second_third.sort(reverse=True)
    for d in range(len(first_second)):
        cnt = 0
        for i in range(N):
            if As[i] % (first_second[d]) == 0:
                cnt += 1
        if cnt >= N-1:
            ans_a = first_second[d]
            break
    for d in range(len(first_third)):
        cnt = 0
        for i in range(N):
            if As[i] % (first_third[d]) == 0:
                cnt += 1
        if cnt >= N-1:
            ans_b = first_third[d]
            break
    for d in range(len(second_third)):
        cnt = 0
        for i in range(N):
            if As[i] % (second_third[d]) == 0:
                cnt += 1
        if cnt >= N-1:
            ans_c = second_third[d]
            break
    print(max(ans_a,ans_b,ans_c))
#for d in range(first_d):
#    cnt = 0
#    for i in range(N):
#        if As[i] % (first_d-d) == 0:
#            cnt += 1
#    if cnt >= N-1:
#        ans = first_d-d
#        break
#print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import copy

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
n = int(input())
A = list(int(i) for i in (input().split()))

ans = 0
tmp = 0
reduce_num = 0
for i in range(n):
  if( i != 0): A.append(reduce_num)
  reduce_num = A.pop(0)
  tmp = gcd_list(A)
  if(ans < tmp):
    ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

from functools import reduce

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

maxv = 0

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

for i in range(N):
    test = Value.copy()
    del test[i]
    if maxv <= gcd_list(test):
        maxv = gcd_list(test)
        
print(maxv)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Alist = list(map(int,input().split()))
all_list = []

def gcd_list(number_list):
    def gcd (a,b):
        if (b == 0):
            return a
        else:
             return gcd (b, a % b)
    res = number_list[0]
    for c in number_list[1::]:
        res = gcd(res , c)
    return res

for i in range(N):
    a_list = []
    for _ in Alist:
        a_list.append(_)
    a_list.pop(i)
    all_list.append(gcd_list(a_list))

print(max(all_list))

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

ans = 0

if n <= 10**3:
    for i in range(n):
        ans = max(gcd_list(a[:i]+a[i+1:]), ans)

    print(ans)
    exit()
else:
    n1 = n//10**3
    n2 = n%10**3

    g = []

    for i in range(n1):
        g.append(gcd_list(a[i*(10**3):(i+1)*(10**3)]))

    if n2 >0:
        g.append(gcd_list(a[n1*(10**3):]))

    for i in range(n):
        memo = g[i//(10**3)]
        g[i//(10**3)] = gcd_list(a[(i//10**3)*(10**3):i] + a[i+1:(i//10**3+1)*(10**3)])
        ans = max(gcd_list(g), ans)
        g[i // (10 ** 3)] = memo
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
 
dic = {}
for a in A:
    divs = make_divisors(a)
    for i in divs:
        if dic.get(i) is None:
            dic[i] = 1
        else:
            dic[i] += 1
 
ans = 0
for k in dic:
    if dic[k] >= N - 1:
        ans = max(ans, k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=tuple(map(int,input().split()))
import fractions
from functools import reduce
ans=0
for i in range(n):
    b=list(a)
    b.pop(i)
    gcd_b=reduce(fractions.gcd,b)
    if ans<gcd_b:
        ans=gcd_b
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
A = list(map(int, input().split(' ')))
count = 0
tmp = 0
for i in range(len(A)):
    A_list = copy(A)
    A_list.pop(i)
    result = reduce(fractions.gcd, A_list)
    if result > count:
        count = result
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
Alist = list(map(int,input().split()))
all_list = []

def gcd_list(number_list):
    def gcd (a,b):
        if (b == 0):
            return a
        else:
             return gcd (b, a % b)
    res = number_list[0]
    for c in number_list[1::]:
        res = gcd(res , c)
    return res

for i in range(N):
    a_list = []
    for _ in Alist:
        a_list.append(_)
    a_list.pop(i)
    all_list.append(gcd_list(a_list))

print(max(all_list))

Submission status: Time Limit Exceeded

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


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


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

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

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


main()

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce
from copy import copy

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

gcds=[]
for i in range(N):
    A_=copy(A)
    A_.pop(i)
    gcds.append(gcd(*A_))

print(max(gcds))

Submission status: Time Limit Exceeded

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

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

A = 0
for i in range(n):
  aa = np.asarray(a)
  a_del = np.delete(a, i, 0)
  List = list(a_del)
  
  G = reduce(gcd,List)
  #print(G)
  A = max(A,G)
print(A)

Submission status: Time Limit Exceeded

Solution code:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
if N == 2:
  print(max(A[0],A[1]))
else:
  ans = -1
  for i in range(N):
    x = -1
    li = [A[i] for i in range(N)]
    li.pop(i)
    for j in range(N-2):
      if j == 0:
        x = fractions.gcd(li[0],li[1])
      else:
        x = fractions.gcd(x,li[j+1])
    if x > ans:
      ans = x
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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


i = 0
max_tmp = 0
max_out = 0

while (i < n):
    
    a1 = a[0:i]
    a2 = a[i+1:n]
    a3 = a1 +a2
    
    max_tmp = reduce(fractions.gcd,a3)
    if max_tmp > max_out:
        max_out = max_tmp

    i += 1

print(max_out)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd


def get_gcd(a):
    mgcd = a[0]
    for i in range(1, len(a)):
        mgcd = gcd(mgcd, a[i])
    return mgcd


N = int(input())
A = list(map(int, input().split()))
mgcd = 0
for i in range(N):
    a = list(A)
    a.pop(i)
    mgcd = max(mgcd, get_gcd(a))
print(mgcd)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)

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


g_max = 1
for i in range(n):
    d = a_l.pop(0)

    if n-1==1:
        g = a_l[0]
    else:
        g = gcd(a_l[0], a_l[1])
        if n-1==2:g=g
        else:
            for j in range(2,n-1):
                g=gcd(g,a_l[j])
    # print(g)
    g_max = max(g, g_max)
    # print(d)
    a_l.append(d)

print(g_max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
values = list(map(int, input().split()))
m = 1


def gcd(x, y):
    if x < y:
        x += y
        y = x - y
        x -= y

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


for i in range(n):
    a = values[:]
    del a[i]
    g = a[0]
    for j in range(n-1):
        if a[j] % g == 0:
            pass
        else:
            g = gcd(g, a[j])
    if m < g:
        m = g

print(m)

Submission status: Time Limit Exceeded

Solution code:
#import math
from functools import reduce

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

    return a


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

for i in range(n):
    aa = a[:]
    aa.pop(i)
    L[i] = reduce(gcd, aa)

print(max(L))

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
import fractions


def main():
    N = int(input())
    num = list(map(int, input().split()))
    # num.sort()
    # print(num)
    # print(num[0:0])
    gcd = 0
    for i in range(len(num)):
        temp_list = num[0:i] + num[i+1:]
        temp_gcd = temp_list[0]
        for i in temp_list:
            temp_gcd = fractions.gcd(temp_gcd, i)
            if temp_gcd < gcd:
                break
        # temp_gcd = functools.reduce(math.gcd, temp_list)
        if temp_gcd > gcd:
            gcd = temp_gcd
    print(gcd)
    # ans = 0
    # print()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd

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

if N == 2:
  print(max(A))
  sys.exit()

g = gcd(A[0], A[1])
#X = set([A[0], A[1]])
X = [A[0], A[1]]

for a in A[2:]:
  XX = [g]
  g = gcd(g, a)
  for x in X:
    XX.append(gcd(x, a))
  X = XX

print(max(X))

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(map(int, input().split()))
ans = gcd_list(a)

for i in range(n):
    a_tmp = a[:]
    del a_tmp[i]
    temp = gcd_list(a_tmp)
    if temp > ans:
        ans = temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

def gcd_list(a):
  tmp = a[0]
  for i in range(len(a)-1):
    tmp = gcd ( a[i+1] , tmp )
  return tmp

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

c=0
for i in range(n):
	c= max(c,gcd_list(v[:i]+v[i+1:]))

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    # divisors.sort(reverse=True)
    return divisors

divs = []
for b in B:
    divs += make_divisors(b)

divs.sort(reverse=True)

ans = 1
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 numpy as np

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

num = 1

for i in range(np.max(A)):
  B = [m for m in A if m % (i + 1) != 0]
  if len(B) == 0 or len(B) == 1:
    num = (i + 1)
    
print(num)

Submission status: Time Limit Exceeded

Solution code:
def divisor(x):
    i = 1
    d = []
    while i*i <= x:
        if x%i == 0:
            d.append(i)
            d.append(x//i)
        i += 1
    return d

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

ans = 1
for i in range(2):
    for d in divisor(a[i]):
        ct = 0
        for j in a:
            if j%d == 0:
                ct += 1
        if ct >= n-1:
            ans = max(ans, d)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
n = int(input())
A = list(map(int, input().split()))

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

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

ans = 0
for i in range(n):
    ans = max(ans, gcd_list(A[0:i] + A[i + 1:]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C問題
N=int(input())
A=list(map(int,input().split()))
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
MAX=0
kari=0
for i in range(N):
    B=A[::]
    del B[i]
    kari=gcdlist(B)
    MAX=max(MAX,kari)
if N == 2:
    MA=max(A)
    g=gcd(A[0],A[1])
    MAX=max(MA,g)
print(MAX)

Submission status: Time Limit Exceeded

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

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

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

gcds = []
for i in range(N):
    A_ = copy(A)
    A_.pop(i)
    gcds.append(gcd(*A_))

print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
n = input()
A = input().split(" ")

n = int(n)
A_tmp = []
for a in A:
    A_tmp.append(int(a))
A = A_tmp

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

if n == 2:
    if A[0] > A[1]:
        print(A[0])
    else:
        print(A[1])
else:
    biggest = 0
    for i in range(n):
        index = []
        for j in range(n):
            if i == j:
                pass
            else:
                index.append(j)

        tmp = euclid(A[index[0]], A[index[1]])
        for j in range(n-1):
            tmp = euclid(tmp ,A[index[j]])

        if tmp > biggest:
            biggest = tmp
    print(biggest)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

def gcd(x,y):
	x_ = max(x,y)
	y_ = min(x,y)
	if y_==0:
		return 0
	if x_%y_==0:
		return y_
	return gcd(y_, x_%y_)

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

gcds = [gcd_list(a[:i]+a[i+1:]) for i in range(n)]

print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
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(A[0], 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
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(A[1], 0, -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)
print(max(result))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# input
n = int(input())
num = [int(a) for a in input().split()]

num.sort()
max = 0

count = 0
for i in range(n-1):
    tmp = num[i] - num[i+1]
    if tmp != 0:
        count = 1
        break
if count == 0:
    print(num[0])
    exit()    

for i in range(1, num[0] + 1):
    count = 0
    for j in range(n):
        tmp = num[j] % int(i)
        if tmp != 0:
            count += 1
        if count > 1:
            break

    if count < 2:
        max = i

print(max)

Submission status: Time Limit Exceeded

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

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

for i in range(len(a)):
	b = a[:]
	b.pop(i)
	res = b[0]
	for c in b[1::]:
		res = gcd(res, c)

	ans = max(ans, res)

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())
AA = [int(i) for i in input().split()]
result = 1
for i in range(N):
    tmp = AA[:i] + AA[i+1:]
    result = max(gcd_list(tmp),result)
print(result)

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

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

    numdct = {}
    for i in range(2):
        for div in make_divisors(a[i]):
            if(not div in numdct):
                numdct[div] = 0
            numdct[div] += 1

    for i in range(2, n):
        for div in make_divisors(a[i]):
            if(not div in numdct):  continue
            numdct[div] += 1
    
    numlist = sorted(numdct.items(), key=lambda x: -x[1])

    maxnum = 0
    for item in numlist:
        if(item[1] >= n - 1):
            if(maxnum <= item[0]):
                maxnum = item[0]
        else:
            break

    print(maxnum)

Submission status: Time Limit Exceeded

Solution code:
import copy
import functools
import fractions
import sys
input = sys.stdin.readline

n=int(input())
lstA=list(map(int,input().split()))
gcdlst=[None]*n

for i in range(n):
    cplstA=copy.copy(lstA)
    del cplstA[i]
    gcdlst[i]=functools.reduce(fractions.gcd, cplstA)

print(max(gcdlst))

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
    return gcd(b, a % b)

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 in xrange(1, n):
        if i == exclude:
            continue
        a = a_list[i]
        g_new = gcd(g, a)
        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(a,b):
    if a > b:
        while b != 0:
            a, b = b, a%b
        return(a)
    else:
        while a != 0:
            b, a = a, b%a
        return(b)        

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

temp = a[0] * a[1]
temp_ = temp
ans = 0
for i in range(n):
    for j in range(n):
        if j != i:
            temp_ = gcd(temp_, a[j])
    if ans < temp_:
        ans = temp_
    temp_ = temp

print(ans)

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce

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

nm = 0

for i in range(n):
  t = gcds(lis[:i]+lis[i+1:])
  if nm < t:
    nm = t
print(nm)