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 collections
from collections import Counter,defaultdict
import copy

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

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

# fact_itmは要素のidexが入力の番号,valueはdict keyが素数でvalueが次数
fact_itm = []
for i in a:
    tmp = prime_factorize(i)
    tmp = collections.Counter(tmp)
    fact_itm.append(tmp)

# print("fact_itm is", fact_itm)

# itm_dictは入力全体に対してその素因数が何個含まれているかのリスト
# keyは素因数,valueはリストでitmeは含まれている個数のリスト
itm_dict = defaultdict(list)

for fact in fact_itm:
    for k, v in fact.items():
        itm_dict[k].append(v)

# print("itme dict", itm_dict)
ans = 0
for now in fact_itm:
    copy_fact = copy.deepcopy(itm_dict)
    for k,v in now.items():
        copy_fact[k].remove(v)

    # print(copy_fact)
    tmp = 1
    for k,v in copy_fact.items():
        if len(v) == n - 1:
            tmp *= k**min(v)

    if ans < tmp:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
for a in A:
    # 約数列挙(1,N)も含まれる
    prime, i = set(), 1
    while i * i <= a:
        if a % i == 0:
            d[i] += 1
            d[a//i] += 1
        i += 1

ans = 1
for i, v in d.items():
    if v+1 >= N:
        ans = max(ans, i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
from collections import defaultdict
d=defaultdict(int)
ans=0
for ai in a:
    b=make_divisors(ai)
    for bi in b:
        d[bi]+=1
        if d[bi]>=n-1:
            ans=max(ans,bi)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
from collections import defaultdict
d=defaultdict(int)
for ai in a:
    b=make_divisors(ai)
    for bi in b:
        d[bi]+=1
ans=0
for k,v in d.items():
    if v>=n-1:
        ans=max(ans,k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
def factorization(n):
    arr = set()
    temp = n
    for i in range(1, int(-(-n**0.5//1))+1):
        if temp%i==0:
            arr.add(i)
            arr.add(temp//i)
    return arr
from collections import defaultdict
d=defaultdict(int)
for ai in a:
    b=factorization(ai)
    for bi in b:
        d[bi]+=1
ans=0
for k,v in d.items():
    if v>=n-1:
        ans=max(ans,k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
class SegmentTree(object):
    def __init__(self, sequence, function, identity):
        N = len(sequence)
        self.length = (1 << (N - 1)).bit_length()
        self.data = [identity] * (self.length << 1)
        self.function = function
        self.identity = identity
        for i in range(N):
            self.data[i + self.length - 1] = sequence[i]
        for i in range(self.length - 2, -1, -1) :
            self.data[i] = self.function(self.data[(i << 1) + 1], self.data[(i << 1) + 2])

    def update(self, idx, x):
        idx += self.length - 1
        self.data[idx] = x
        while idx:
            idx = (idx - 1) >> 1
            self.data[idx] = self.function(self.data[(idx << 1) + 1], self.data[(idx << 1) + 2])

    def query(self, p, q):
        if q <= p:
            return self.identity
        p += self.length - 1
        q += self.length - 2
        res = self.identity
        while q - p > 1:
            if not p & 1:
                res = self.function(res, self.data[p])
            if q & 1:
                res = self.function(res, self.data[q])
                q -= 1
            p >>= 1
            q = (q - 1) >> 1
        return self.function(res, self.data[p]) if p == q else self.function(self.function(res, self.data[p]), self.data[q])

N, *A = map(int, open(0).read().split())
seg_tree = SegmentTree(A, gcd, 0)
ans = 0
for i in range(N):
    seg_tree.update(i, 0)
    ans = max(ans, seg_tree.query(0, N))
    seg_tree.update(i, A[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
# from fractions import gcd

from fractions import gcd
def lcm(x, y):
  return x // gcd(x, y) * y

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 sorted(divisors, reverse=True)

def solve():
    N = II()
    A = LI()

    p = 1
    l = 1
    for a in A:
        l = lcm(p, a)
        p = a

    div = make_divisors(l)

    for d in div:
        no = 1
        for a in A:
            if a % d == 0:
                continue
            else:
                no -= 1
                if no < 0:
                    break
        else:
            print(d)
            return
    print(1)



if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)[::-1]
"""
あるn以外の最大公約数が, 最大になる組み合わせ
7 6 8 -> gcd(7,6)=1, gcd(6,8)=2 gcd(7,8)=1
12 15 18 -> gcd(12,15)=3, gcd(15,18)=3, gcd(12, 18)=6
1 2 4 6 -> 2,4,6のやつがでかい
"""
if n == 2:
	print(a[0])
	exit()
ans = 0
for i in range(n):
	tmp = 0
	for j in range(n):
		if j != i:
			tmp = gcd(tmp, a[j])
		if tmp < ans:
			break
	ans = max(tmp, ans)
print(ans)

Submission status: Time Limit Exceeded

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

from fractions import gcd
magcd = 0
for i in range(N):
  a = 0
  for j in range(i):
    a = gcd(a,A[j])
  b = 0
  for k in range(i+1,N)[::-1]:
    b = gcd(b,A[k])
  ggc = gcd(a,b)
  if ggc > magcd:
    magcd = ggc
print(magcd)

Submission status: Time Limit Exceeded

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

from fractions import gcd
magcd = 0
for i in range(N):
  a = 0
  for j in range(i):
    a = gcd(a,A[j])
  b = 0
  for k in range(i+1,N):
    b = gcd(b,A[k])
  ggc = gcd(a,b)
  if ggc > magcd:
    magcd = ggc
print(magcd)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
g=1
a=sorted(a)

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

for i in range(n):
    b=a.copy()
    b.pop(i)
    if min(b)<g:
        pass
    else:
        if g < gcd(b):
            g = gcd(b)
print(g)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
g=1
a=sorted(a)

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

for i in range(n):

    b=a.copy()
    
    b.pop(i)
    if g < gcd(b):
        g = gcd(b)
print(g)

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):
    left, right = A[: i], A[i + 1: ]
    gcd_left, gcd_right = 0, 0
    for l in left:
        gcd_left = gcd(gcd_left, l)
    for r in right:
        gcd_right = gcd(gcd_right, r)

    ans = max(ans, gcd(gcd_left, gcd_right))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

def gcd_list(nums):
    if len(nums) == 0:
        return 0
    return reduce(fractions.gcd, nums)

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

ans = 0
for i in range(n):
    l, r = gcd_list(A[: i]), gcd_list(A[i + 1: ])
    ans = max(ans, fractions.gcd(l, r))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
import math
n = int(input())
a = list(map(int, input().split()))
def prime(k):
    for divisor in range(2, math.floor(math.sqrt(k))+1):
        if k % divisor == 0:
            return False
    return True


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


prime_count = 0
data = []
for i in range(n):
    if prime(a[i]):
        prime_count += 1
        if prime_count >= 2:
            print(1)
            exit()
    else:
        data.append(a[i])

if prime_count == 1:
    ans = _gcd(data)
else:
    data.sort()
    ans = 0
    for i in range(n):
        p = _gcd(data[:i]+data[i+1:])
        if p > ans:
            ans = p

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
import fractions
import collections
 
gcd_s = []
for i in range(n):
    tem_arr = []
    if i != 0:
        tem_arr += a[:i]
    if i != n-1:
        tem_arr += a[i+1:]
    tem_arr = collections.deque(tem_arr)
    tem_gcd = tem_arr.popleft()
    len_tem = len(tem_arr)
    for j in range(len_tem):
        tem = tem_arr.popleft()
        tem_gcd = fractions.gcd(tem_gcd, tem)
    gcd_s.append(tem_gcd)
    
print(max(gcd_s))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
#累積GCD
left = [0]
right = [0]
for i in range(N):
  left.append(fractions.gcd(left[i],A[i]))
  right.insert(0,fractions.gcd(right[0],A[N-1-i]))

ans = 0
for i in range(N):
  ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
result = [0]*N
tmp = 0
for i in range(N):
  tmp = A.pop(i)
  result[i] = reduce(fractions.gcd, A)
  A.insert(i,tmp)

print(max(result))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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

#a = [746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#a = [7,6,8]
#n = len(a)
max_value = 0
for i in range(n):
    memo = a.pop(0)
    x = reduce(gcd, a)
    if x > max_value:
        max_value = x
    a.append(memo)
print(max_value)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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

#a = [746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#a = [7,6,8]
#n = len(a)
max_value = 0
for i in range(n):
    b = a.copy()
    b.pop(i)
    x = reduce(gcd, b)
    if x > max_value:
        max_value = x
        max_pos = i
print(max_value)

Submission status: Time Limit Exceeded

Solution code:
# abc125_c.py
import math
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()))
max_gcd = 1
prime_cnt = 0
for i in range(N):
    A_tmp = A[:i] + A[i+1:]
    # print(A[:i], A[i+1:], A[:i] + A[i+1:])
    target = gcd_list(A_tmp)
    if max_gcd < target:
        max_gcd = target
print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

def GCD(*numbers):
    return reduce(gcd, numbers)

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

ans=0
for i in range(n):
    b=a[:i]+a[i+1:]
    ans=max(ans,GCD(*b))
    if ans==max(a):
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

def GCD(*numbers):
    return reduce(gcd, numbers)

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

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 sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans = max(ans, gcd_list(a[:i] + a[i + 1:]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
def gcd_list(nums):
    return reduce(gcd, nums)
n=int(input())
l=list(map(int,input().split()))
a=1
for i in range(n):
    t=l[:i]+l[i+1:]
    a=max(a,gcd_list(t))
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math
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())

list = list(map(int,input().split()))
ans2 = 0

for i in range(N):
  l = list[0:i]
  
  if -(N-i)+1 == 0:
    r = []
  else:
    r = list[-(N-i)+1:]
    
  if l == []:
    ans = gcd_list(r)
  elif r == []:
    ans = gcd_list(l)
  else:
    a = gcd_list(r)
    b = gcd_list(l)
    ans = gcd(a, b)
    
  ans2 = max(ans2,ans)
  
print(ans2)

Submission status: Time Limit Exceeded

Solution code:
def dv(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
N = int(input())
A = list(map(int,input().split()))
l=[]
cnt = 0
for i in set(dv(A[0])+dv(A[1])):
    cnt = 0
    for j in range(len(A)):
        if A[j]%i == 0:
            cnt += 1
    if cnt >= N-1:
        l.append(i)
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    while num[0]<count and any([x%count!=0 for x in num[1::]]):
        count=int(count/2)
for i in range(count+1)[::-1]:
    is_i=0
    for j in data:
        if j%i!=0:
            is_i+=1
    if is_i<=1:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    while num[0]<count and any([x%count!=0 for x in num[1::]]):
        count=int(count/2)
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    while num[0]<count and any([x%count!=0 for x in num[1::]]):
        count=int(count/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    for j in range(len(data)):
        if data[j]%i!=0:
            is_i+=1
    if is_i<=1:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    while num[0]<count and any([x%count!=0 for x in num[1::]]):
        count=int(count/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    if num[0]!=num[1] and any([x%num[1]!=0 for x in num[1::]]):
        count=int(num[1]/2+1)
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    if num[0]!=num[1] and any([x%num[1]!=0 for x in data[1::]]):
        count=int(num[1]/2+1)
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if num[0]!=num[1]:
    if any([x%num[1]!=0 for x in data[1::]])==True:
        count=int(num[1]/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if num[0]!=num[1] and any([x%num[1]!=0 for x in data[1::]])==True:
    count=int(num[1]/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if num[0]!=num[1] and all([x%num[1]==0 for x in data[1::]])==False:
    count=int(num[1]/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if 2<len(data):
    if num[0]!=num[1] and num[1]!=num[2]:
        count=int(num[1]/2+1)
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=0
for i in range(num[1]+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    elif count==0:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
"""
GCD on Blackboard
"""
import fractions
from functools import reduce

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

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

G = [0] * N
for i in range(N):
    t = [A[j] for j in range(len(A)) if j != i]
    G[i] = gcd(*t)

print(max(G))

Submission status: Time Limit Exceeded

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


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


left = [gcd(an[:i]) for i in range(1, n)]
right = [gcd(an[i:]) for i in range(1, n)]

ans = 0
ans = max(ans, right[0], left[-1])
for i in range(1, n-1):
    ans = max(ans, fractions.gcd(left[i-1], right[i]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(N):
    A_ = np.concatenate([A[:i], A[i+1:]])
    a = np.gcd.reduce(A_)
    ans = max(ans, a)

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

#リスト l の最大公約数
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

gcd_ref = [A[0]]

for i in range(1, N):
    new_gcd = gcd(gcd_ref[-1], A[i])
    gcd_ref.append(new_gcd)
    
best = gcd_ref[N - 1]
for i in range(N - 1, -1, -1):
    if i > 0:
        if i == N - 1:
            a = gcd_ref[i - 1]
            if best < a:
                best = a
        else:
            a = gcd_ref[i - 1]
            l = A[i + 1:]
            gcd_without_i = gcd(a, gcdlist(l))
            if gcd_without_i > best:
                best = gcd_without_i
    else:
        l = A[1:]
        gcd_without_i = gcdlist(l)
        if gcd_without_i > best:
            best = gcd_without_i

print(best)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
n = int(input())
A = list(map(int, input().split()))
def left(i):
    if i < 1:
        return 0
    return gcd(left(i-1), A[i-1])
def right(i):
    if i+1 > n-1:
        return 0
    return gcd(right(i+1), A[i+1]) 
ans = 0
for i in range(n):
    ans = max(ans, gcd(left(i), right(i)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
n = int(input())
A = list(map(int, input().split()))
def left(i):
    if i < 1:
        return 0
    return gcd(left(i-1), A[i-1])
def right(i):
    if i+1 > n-1:
        return 0
    return gcd(right(i+1), A[i+1])
ans = 0
for i in range(n):
    ans = max(ans, gcd(left(i), right(i)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
n = int(input())
A = list(map(int, input().split()))
ans = 0
def gcdEx(L, a):
    if A[0] == a:
        g = A[1]
    else:
        g = A[0]
    for l in L:
        if l != a:
            g = gcd(l, g)
    return g
for a in A:
    tmp = gcdEx(A, a)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
class ABSsegtree: # 必要な配列の長さN,単位元ie,関数(2項演算)func,を渡す    
    def __init__(self,N,ie,func):
        self.func=func
        self.getLEN=1 # Length of list
        while self.getLEN<N:
            self.getLEN*=2
        self.getsize=self.getLEN*2 # =len(ST)
        self.getLIN=self.getsize-self.getLEN # internal nodes without ST[0]
        self.ST=[ie]*self.getsize

    def update(self,i,x): # i(0-index)にxをいれる
        i+=self.getLIN
        self.ST[i]=x
        while i>1:
            i//=2
            self.ST[i]=self.func(self.ST[2*i],self.ST[2*i+1])
    
    def get_interval(self,a,b): # [a,b)での最小値を求めたい
        a+=self.getLIN
        b+=self.getLIN
        ret=self.func(self.ST[a],self.ST[b-1])
        while a+1<b: # 階層ごとに見る
            if a%2==1:
                ret=self.func(self.ST[a],ret)
                a+=1
            a//=2
            if b%2==1:
                ret=self.func(self.ST[b-1],ret)
            b//=2
        if a==b:
            pass
        else:
            ret=self.func(ret,self.ST[a])
        return ret
      
import fractions

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

ins=ABSsegtree(N,0,fractions.gcd)
for i,a in enumerate(A):
  ins.update(i,a)
ans=0
for i,a in enumerate(A):
  ins.update(i,0)
  ans=max(ans,ins.get_interval(0,N))
  ins.update(i,a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import copy
from functools import reduce
import fractions
n = int(input())
a = list(map(int, input().split()))



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

maximum = 0
for i in range(n):
    l = copy.deepcopy(a)
    del l[i:i+1]
    maximum = max(maximum, gcd(l))


print(maximum)

Submission status: Time Limit Exceeded

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

def gcd(a,b):
  aa=max(a,b)
  bb=min(a,b)
  return gcd(bb,aa%bb) if bb else aa
  

temp=0
for i in range(0,n):
  l_gcd=0
  r_gcd=0
  lis_left=a[:i]
  try:
    lis_right=a[i+1:]
  except IndexError:
    lis_right=[]
  if lis_left:
    for j in range(0,len(lis_left)):
      l_gcd=gcd(l_gcd,lis_left[j])
  if lis_right:
    for j in range(0,len(lis_right)):
      r_gcd=gcd(r_gcd,lis_right[j])
  gcdgcd=gcd(l_gcd,r_gcd)
  if gcdgcd>temp:
    temp=gcdgcd

print(temp)