Problem:


Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

for i in range(N):
    gcd_res[i] = gcd_list(A[:i] + A[i+1:])

print(max(gcd_res))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    bigger = max(a, b)
    smaller = min(a, b)
    while smaller != 0:
        bigger, smaller = smaller, bigger % smaller
    return bigger


def gcd_seq(seq):
    ans = seq[0]
    for n in seq:
        ans = gcd(ans, n)
    return ans


N = int(input())
A = list(map(int, input().split()))
GCD = [gcd_seq(A[:i] + A[i + 1:]) for i in range(N)]
print(max(GCD))

Submission status: Time Limit Exceeded

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

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

ans = [0]*n
for i in range(n):
  litmp = li[:i] + li[i+1:]
  tmp = litmp[0]
  for j in range(1,n-1):
    tmp = gcd(tmp,litmp[j])
  ans[i] = tmp
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import functools
from fractions import gcd
import copy

N = int(input())
A = list(map(int, input().split()))
maxGcd = functools.reduce(gcd, A)
for i in range(N):
    tempA = copy.deepcopy(A)
    tempA.pop(i)
    tempGcd = functools.reduce(gcd, tempA)
    maxGcd = max(maxGcd, tempGcd)
print(maxGcd)

Submission status: Time Limit Exceeded

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

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

l = list(itertools.combinations(a,n-1))
ans = 0

for itr in l:
    ans = max(ans, reduce(gcd, list(itr)))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x,y):
    if x<y:
        return(gcd(y,x))
    elif y==0:
        return(x)
    else:
        return(gcd(y,x%y))

N = int(input())
A = list(map(int,input().split()))
g = A[0]
H = []
B = A

for j in range (N):
    g = 0
    subs=A[j]
    B[j]=0
    for i in range(N):
        g = gcd(g,B[i])
    H.append(g)
    B[j] = subs    

print(max(H))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

def gcd_pop(L,I,N):
  L1=L[0:I]
  L2=L[I+1:N]
  L1.extend(L2)
  return gcd_list(L1)
max_l=0
for i in range(n):
  if max_l<gcd_pop(a,i,n):
    max_l=gcd_pop(a,i,n)

print(max_l)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

def gcd_pop(L,I,N):
  L1=L[0:I]
  L2=L[I+1:N]
  L1.extend(L2)
  return gcd_list(L1)

l=[gcd_pop(a,i,n) for i in range(n)]

print(max(l))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

l=[]
for i in range(n):
  b=a.copy()
  b.pop(i)
  l.append(gcd_list(b))
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
import sys, copy

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y) #再帰定義

def listgcd(A):
	newA = []
	if len(A) % 2 == 1:
		A.append(0)
	
	for i in range(0, len(A), 2):
		newA.append(gcd(A[i], A[i + 1]))
	
	if len(newA) == 1:
		return newA[0]
	else:
		return listgcd(newA)
	
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

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

ans = 0

for i in range(N):
	B = copy.copy(A)
	B[i] = 0
	tmp = listgcd(B)
	if ans < tmp:
		ans = tmp
		
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

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

gcd_all = reduce(gcd, A)

for i in range(N):
    gcd_1 = reduce(gcd, (A[:i]+A[i+1:]))
    if gcd_1 >= gcd_all:
        gcd_all = gcd_1

print(gcd_all)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

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

gcd_all = functools.reduce(fractions.gcd, A)

for i in range(N):
    gcd_1 = functools.reduce(fractions.gcd, (A[:i]+A[i+1:]))
    if gcd_1 >= gcd_all:
        gcd_all = gcd_1

print(gcd_all)

Submission status: Time Limit Exceeded

Solution code:
import functools
#import math
import fractions

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

#gcd_all = functools.reduce(math.gcd, A)
gcd_all = functools.reduce(fractions.gcd, A)

for i in range(N):
    #gcd_1 = functools.reduce(math.gcd, list)
    gcd_1 = functools.reduce(fractions.gcd, (A[:i]+A[i+1:]))
    if gcd_1 >= gcd_all:
        gcd_all = gcd_1

print(gcd_all)

Submission status: Time Limit Exceeded

Solution code:
import functools
#import math
import fractions

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

#gcd_all = functools.reduce(math.gcd, A)
gcd_all = functools.reduce(fractions.gcd, A)
#print(gcd_all)

for i in range(N):
    #list = A[:i] + A[i+1:]
    #print(list)
    #gcd_1 = functools.reduce(math.gcd, list)
    gcd_1 = functools.reduce(fractions.gcd, (A[:i]+A[i+1:]))
    #print(gcd_1)
    if gcd_1 >= gcd_all:
        #index = i
        #value = gcd_1
        gcd_all = gcd_1

#A[index] = value

#print(functools.reduce(math.gcd, A))
#print(functools.reduce(fractions.gcd, A))
print(gcd_all)

Submission status: Time Limit Exceeded

Solution code:
import functools
#import math
import fractions

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

#gcd_all = functools.reduce(math.gcd, A)
gcd_all = functools.reduce(fractions.gcd, A)
#print(gcd_all)

for i in range(N):
    list = A[:i] + A[i+1:]
    #print(list)
    #gcd_1 = functools.reduce(math.gcd, list)
    gcd_1 = functools.reduce(fractions.gcd, list)
    #print(gcd_1)
    if gcd_1 >= gcd_all:
        #index = i
        #value = gcd_1
        gcd_all = gcd_1

#A[index] = value

#print(functools.reduce(math.gcd, A))
#print(functools.reduce(fractions.gcd, A))
print(gcd_all)

Submission status: Time Limit Exceeded

Solution code:
import functools
import math
import fractions

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

#gcd_all = functools.reduce(math.gcd, A)
gcd_all = functools.reduce(fractions.gcd, A)
#print(gcd_all)

for i in range(N):
    list = A[:i] + A[i+1:]
    #print(list)
    #gcd_1 = functools.reduce(math.gcd, list)
    gcd_1 = functools.reduce(fractions.gcd, list)
    #print(gcd_1)
    if gcd_1 >= gcd_all:
        #index = i
        #value = gcd_1
        gcd_all = gcd_1

#A[index] = value

#print(functools.reduce(math.gcd, A))
#print(functools.reduce(fractions.gcd, A))
print(gcd_all)

Submission status: Time Limit Exceeded

Solution code:
import functools
import math
import fractions

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

#gcd_all = functools.reduce(math.gcd, A)
gcd_all = functools.reduce(fractions.gcd, A)
#print(gcd_all)

for i in range(N):
    list = A[:i] + A[i+1:]
    #print(list)
    #gcd_1 = functools.reduce(math.gcd, list)
    gcd_1 = functools.reduce(fractions.gcd, list)
    #print(gcd_1)
    if gcd_1 >= gcd_all:
        index = i
        value = gcd_1
        gcd_all = gcd_1

A[index] = value

#print(functools.reduce(math.gcd, A))
print(functools.reduce(fractions.gcd, A))

Submission status: Time Limit Exceeded

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

n = int(input())
a = list(map(int,input().split()))
max_ = 0
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

for i in range(n) :
    b = copy(a)
    b.pop(i)
    c = gcd_list(b)
    if max_ <= c:
        max_ = c

print(max_)

Submission status: Time Limit Exceeded

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

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

M = []
for i in range(N):
    M.append(gcd(L[i], R[i+1]))
print(max(M))

Submission status: Time Limit Exceeded

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

max_gcd_list = []
for i in range(N):
    new_list = a_list[:i] + (a_list[(i+1):] if i < N-1 else [])
    max_gcd = reduce(gcd, new_list[1:], new_list[0])
    max_gcd_list.append(max_gcd)
print(max(max_gcd_list))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
a=input().split(" ")
a=[int(j) for j in a]
divised=0
from fractions import gcd
from functools import reduce
divisor=reduce(gcd,a)
b=[]
for i in range(n):
    b=a[:i]+a[i+1:]
    divised=reduce(gcd,b)
    if divisor<divised:
        divisor=divised
print(divisor)

Submission status: Time Limit Exceeded

Solution code:
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_3.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = gcd(data[2 * k + 1], data[2 * k + 2])


# 区間[l, r)の最小値
def query(l, r):
    L = l + N0
    R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = gcd(s, data[R-1])

        if L & 1:
            s = gcd(s, data[L-1])
            L += 1
        L >>= 1
        R >>= 1
    return s


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    # N: 処理する区間の長さ
    N0 = 2**(N-1).bit_length()
    INF = 2**31-1
    data = [0] * (2 * N0)

    # write code
    for num, i in enumerate(A):
        update(num, i)

    ans = 0
    for i in range(N):
        ans = max(ans, gcd(query(0, i), query(i + 1, N)))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from  fractions import gcd
N=int(input())
A=list(map(int,input().split()))
L=[0]
R=[0]
ans=1
for i in range(N-1):
    R.append(gcd(R[-1], A[::-1][i]))
    L.append(gcd(L[-1], A[i]))
print(max(gcd(l,r)for l,r in zip(L,R[::-1])))

Submission status: Time Limit Exceeded

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
L=[0]
R=[0]
ans=1
for i in range(N):
    if i==N-1:
        pass
    else:
        R.append(fractions.gcd(R[-1], A[::-1][i]))
        L.append(fractions.gcd(L[-1], A[i]))
print(max(fractions.gcd(l,r)for l,r in zip(L,R[::-1])))

Submission status: Time Limit Exceeded

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
L=[0]
R=[0]
ans=1
for i in range(N):
    if i==N-1:
        pass
    else:
        R.append(fractions.gcd(R[-1], A[::-1][i]))
        L.append(fractions.gcd(L[-1], A[i]))
for j in range(N):
    ans=max(ans,fractions.gcd(L[j],R[(N-1)-j]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def euclid(a, b):
    mod = a % b
    if mod != 0:
        b = euclid(b, mod)
    return b
N = int(input())
A = [int(a) for a in input().split()]
gcd_lis = []
for i in range(N):
    X = A[:i]+A[i+1:]
    gcd = X[0]
    for x in X:
        gcd = euclid(gcd, x)
    gcd_lis.append(gcd)
maximam = 1
for j in gcd_lis:
    maximam = max(maximam, j)
print(maximam)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n = int(input())
A = list(map(int, input().split()))
M = []
for i in range(n):
    target_index = i
    if target_index == 0:
        target = A[1]
    else:
        target = A[0]
    for index, number in enumerate(A):
        if index == target_index:
            continue
        target = fractions.gcd(target, number)
    M.append(target)
print(max(M))

Submission status: Time Limit Exceeded

Solution code:
import fractions
N = int(input())
aLst = list(map(int, input().split()))

ansLst = []
for i in range(len(aLst)):
    ans = 0
    for j in range(len(aLst)):
        if i != j:
            ans = fractions.gcd(ans, aLst[j])
    ansLst.append(ans)
ansLst.sort(reverse=True)
print(ansLst[0])

Submission status: Time Limit Exceeded

Solution code:
import sys
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
# from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
# dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
a = wi()

value = [] # ノードの値を持つ配列
N = 0 # 葉の数

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

def update(i, x):
    # i番目の葉の値をxに変える
    i += N - 1  # i番目の葉のノード番号
    value[i] = x
    while i > 0:
        i = (i - 1) / 2  # ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1], value[i * 2 + 2])  # 左右の子の min を計算しなおす


#define INF 2147483647 // 2^31-1
INF = float("INF")
def query(a, b, k, l, r) :
    # [a, b) の区間に対するクエリについて
    # ノード k （区間 [l, r) 担当）が答える
    if r <= a or b <= l:
        # 区間が被らない場合は INF を返す
        return 0
    if a <= l and r <= b:
        # ノード k の担当範囲がクエリ区間 [a, b) に完全に含まれる
        return value[k]
    else:
        # 一部だけ範囲が被る場合は左右の子に委託する
        c1 = query(a, b, 2 * k + 1, l, (l + r) // 2)  # 左の子に値を聞く
        c2 = query(a, b, 2 * k + 2, (l + r) // 2, r)  # 右の子に値を聞く
        # 左右の子の値の min を取る
        return gcd(c1, c2)



value = [] # ノードの値を持つ配列
N = 0 # 葉の数

if __name__ == '__main__':
    N = 1
    while N < n:
        N *= 2  # 葉の数を計算（n以上の最小の2冪数）

    value = [0] * (2 * N - 1)
    for i in reversed(range(2 * N - 1)):
        if N - 1 <= i < 2 * N - 1:
            if N - 1 <= i < N - 1 + n:
                value[i] = a[i - (N - 1)]
            else:
                value[i] = 0
        else:
            value[i] = gcd(value[2 * i + 1], value[2 * i + 2])

    for i in range(n):#query(,,0,0,N)
        if i == 0:
            ansli.append(query(1, n, 0, 0, N))
        elif i == n - 1:
            ansli.append(query(0, n - 1, 0, 0, N))
        else:
            ansli.append(gcd(query(0, i, 0, 0, N), query(i + 1, n, 0, 0, N)))
print(max(ansli))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import fractions
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()))
key=[]

for j in range(N):
    if j!=0: tmp.insert(j-1,P)
    tmp=a[:]
    P=tmp.pop(j)
    
    for i in range(N):
        ans=gcd_list(tmp)

    key.append(ans)
print(max(key))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

keys = set()

def factorize(n):
    fct = defaultdict(int)
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct[b] = e
        b, e = b + 1, 0
    if n > 1:
        fct[n] = 1

    for k, v in fct.items():
        keys.add(k)
    return fct
list(map(factorize, A))


max_factors = defaultdict(list)

def factorize2(n):
    fct = {}
    b, e = 2, 0
    for b in keys:
        while n % b == 0:
            n = n // b
            e = e + 1
        fct[b] = e
        max_factors[b].append(e)
        max_factors[b] = sorted(max_factors[b])[:2]
        b, e = b + 1, 0
    return fct
fcts = list(map(factorize2, A))

_res = 1

def it(fct):
    res = 1
    for k, ar in max_factors.items():

        if ar[0] == fct[k]:
            if len(ar) > 1:
                res *= k**ar[1]
        else:
            res *= k**ar[0]
    return res

print(max(it(fct) for fct in fcts))

Submission status: Time Limit Exceeded

Solution code:
import sys
inp = sys.stdin.readline
n = int(inp())
a = list(map(int,inp().split()))
def gcd(a,b):
    if a < b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a
ans = 1
for i in range(n):
    _a = a[:]
    # _a.pop(i)
    tmp = _a[i+1] if i != n-1 else _a[0]
    for j in range(n):
        if j != i:
            tmp = gcd(tmp,_a[j])
        else:
            pass
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

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

ans = 1
tmp = 0
for i in range(n):
    _a = a[:]
    _a.pop(i)
    tmp = _a[0]
    for j in range(n-1):
        tmp = gcd(tmp,_a[j])
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 1
tmp = 0
for i in range(n):
    _a = a[:]
    _a.pop(i)
    tmp = _a[0]
    for j in range(n-1):
        tmp = gcd(tmp,_a[j])
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
a=input().split(" ")
a=[int(j) for j in a]
a.sort()
count=0
divisor=0
divised=0
interrupt=0

#最大
divisor=max(a[0:2])
for i in range(n):
    if a[i]%divisor!=0:
        count=count+1
if count<2:
    divised=divisor
    interrupt=1

count=0

#最大でなかった時
if interrupt==0:
    for divisor in reversed(range(1,max(a[0:2])//2+1)):
        for i in range(n):
            if a[i]%divisor!=0:
                count=count+1
        if count<2:
            divised=divisor
            break
        count=0
        
print(divised)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
a=input().split(" ")
a=[int(j) for j in a]
a.sort()
count=0
divisor=0
divised=0
for divisor in range(1,max(a[0:2])+1):
    for i in range(n):
        if a[i]%divisor!=0:
            count=count+1
    if count<2:
        divised=divisor
    count=0
print(divised)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
a=input().split(" ")
a=[int(j) for j in a]
count=0
divisor=0
divised=0
for divisor in range(1,max(a[0:2])+1):
    for i in range(n):
        if a[i]%divisor!=0:
            count=count+1
    if count<2:
        divised=divisor
    count=0
print(divised)

Submission status: Time Limit Exceeded

Solution code:
import fractions  
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
b = 1
if N == 2:
  b = max(A)
else :
  for i in range(N):
    L= sorted(A[:i]+A[i+1:])
    for j in range(N-1):
      if j == 0:
        C = fractions.gcd(L[0],L[1])
        if C <= b :
          break
      elif  j == N-2:
        C = fractions.gcd(C,L[j])
        if C <= b :
          break
        elif C > b:
          b = C  
      else :
        C = fractions.gcd(C,L[j])
        if C <= b :
          break
print(b)

Submission status: Time Limit Exceeded

Solution code:
import fractions  
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
b = reduce(fractions.gcd,A[:0]+A[1:])
if N == 2:
  b = max(A)
else :
  for i in range(1,N):
    L= sorted(A[:i]+A[i+1:])
    for j in range(N-1):
      if j == 0:
        C = fractions.gcd(L[0],L[1])
        if C <= b :
          break
      elif  j == N-2:
        C = fractions.gcd(C,L[j])
        if C <= b :
          break
        elif C > b:
          b = C  
      else :
        C = fractions.gcd(C,L[j])
        if C <= b :
          break
print(b)

Submission status: Time Limit Exceeded

Solution code:
import fractions  
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
b = reduce(fractions.gcd,A[:0]+A[1:])
if N == 2:
  b = max(A)
else :
  for i in range(1,N):
    L= A[:i]+A[i+1:]
    for j in range(N-1):
      if j == 0:
        C = fractions.gcd(L[0],L[1])
        if C < b :
          break
      elif  j == N-2:
        C = fractions.gcd(C,L[j])
        if C <= b :
          break
        elif C > b:
          b = C  
      else :
        C = fractions.gcd(C,L[j])
        if C <= b :
          break
print(b)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools
from functools import reduce


def shift(index: int, l: list) -> list:
    return l[index:] + l[:index]


def not_see_one(index: int, a: list) -> iter:
    ret = shift(index, a)
    return ret[1:]


def gcd_list(numbers: list) -> int:
    return reduce(fractions.gcd, numbers)


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

result = max(map(gcd_list, map(functools.partial(not_see_one, a=a_list), range(n))))
print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce 

def mygcd(nlist) :
	return reduce(fractions.gcd,nlist)

N = int(input())
A = list(map(int,input().split()))
res = 0
for i in range(N) :
	new = A.copy()
	del new[i]
	a = mygcd(new)
	if a > res :
		res = a
print(res)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce


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


'''
def lcm(a, b):
    return a * b // gcd(a, b)
'''
n = int(input())
a_list = list(map(int, input().split()))
remove_list = a_list[:]
re_max = 0

for i in range(len(a_list)):
    remove_list.pop(i)
    re_max = max(re_max, reduce(gcd, remove_list))
    remove_list = a_list[:]

print(re_max)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce 

def mygcd(nlist) :
	return reduce(fractions.gcd,nlist)

N = int(input())
A = list(map(int,input().split()))
res = 0
for i in range(N) :
	new = A.copy()
	del new[i]
	if mygcd(new) > res and res != 1 :
		res = mygcd(new)
print(res)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
'''
def lcm(a, b):
    return a * b // gcd(a, b)
'''
n = int(input())
a_list = list(map(int, input().split()))
remove_list = a_list[:]
max_list = []

for i in range(len(a_list)):
    remove_list.pop(i)
    max_list.append(reduce(gcd, remove_list))
    remove_list = a_list[:]

print(reduce(max, max_list))

Submission status: Time Limit Exceeded

Solution code:
import copy
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
l=1
for i in A:
    if len(A)>=3:
        B=copy.deepcopy(A)
        B.remove(i)
        l=max(reduce(fractions.gcd,B),l)
    else:
        l=max(i,l)
print(l)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
l=[]
for i in A:
    if len(A)>=3:
        B=copy.deepcopy(A)
        B.remove(i)
        l.append(reduce(fractions.gcd,B))
    else:
        l.append(i)
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
import fractions 
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
def gcd(L):
    return reduce(fractions.gcd, L)
b = 0
for i in range(N):
  if b < gcd(A[:i]+A[i+1:]):
    b = gcd(A[:i]+A[i+1:])
print(b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
in_num = input().split()
lis_num = [int(s) for s in in_num]
m = max(lis_num)

x = [lis_num[i] % m for i in range(n)]
sx = sorted(x)
m2 = sorted(lis_num)[n-2]
y = [lis_num[i] % m2 for i in range(n)]
sy = sorted(y)
if sx[n-2] == 0:
  ans = m
elif sy[n-2] == 0:
  ans = m2
else:
  for i in range((m+1)//2, 0, -1):
    x = [lis_num[j] % i for j in range(n)]
    sx = sorted(x)
    if sx[n-2] == 0:
      ans = i
      break
    else:
      continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
in_num = input().split()
lis_num = [int(s) for s in in_num]
m = max(lis_num)

x = [lis_num[i] % m for i in range(n)]
sx = sorted(x)
if sx[n-2] == 0:
  ans = m
else:
  for i in range(m-1, 0, -1):
    x = [lis_num[j] % i for j in range(n)]
    sx = sorted(x)
    if sx[n-2] == 0:
      ans = i
      break
    else:
      continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
in_num = input().split()
lis_num = [int(s) for s in in_num]
m = max(lis_num)

x = np.array(lis_num) % m
sx = sorted(x)
if sx[n-2] == 0:
  ans = m
else:
  for i in range(m-1, 0, -1):
    x = np.array(lis_num) % i
    sx = sorted(x)
    if sx[n-2] == 0:
      ans = i
      break
    else:
      continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
def gcd(a, b):
  l = max(a, b)
  s = min(a, b)
  if s == 0:
    return l
  else:
    return gcd(s, l%s)

n = int(input())
As = list(map(int, input().split(" ")))
largest = 0
for i in range(n):
  largest = max(largest, gcd(reduce(gcd, As[:i], 0), reduce(gcd, As[i+1:], 0)))
  
print(largest)

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
from functools import reduce

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

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    l = []
    l2 = []
    for i in range(N):
    
        l2 = copy.deepcopy(A)
        l2.pop(i)
        l.append(gcd_list(l2))
    
    print(max(l))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
from functools import reduce

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

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    l = []
    A_max = max(A)
    for i in range(N):
        l2 = copy.deepcopy(A)
        l2[i] = A_max
        l.append(gcd_list(l2))
    
    print(max(l))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
from functools import reduce

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

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    l = []
    for i in range(N):
        l2 = copy.deepcopy(A)
        l2[i] = max(A)
        l.append(l2)
    
    ans = [gcd_list(l3) for l3 in l]
    
    print(max(ans))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools
import copy
N = int(input())
A = list(map(int,input().split()))
max = 0
for i in range(N):
    a = copy.copy(A)
    a.pop(i)
    gcd = functools.reduce(fractions.gcd,a)
    if gcd>max:
        max = gcd
print(max)

Submission status: Time Limit Exceeded

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

# print(n)
# print(aList)

# 最大公約数を求めてみる
def getGCD(a,b):
	x = a
	y = b
	if b > a :
		x = b
		y = a
	
	while True:
		# print(x,y)

		amari = x % y

		if amari == 0:
			gcd = y
			return gcd
			break

		x = y
		y = amari

#print(getGCD(100000,15000))


# 最大公約数を求めてみる
def getGCD_List(numList):
	if len(numList) == 1:
		return numList[0]

	gcd = getGCD(numList[0], numList[1])
	for i in range(2, len(numList)) :
		y = numList[i]
		

		# print(gcd,y)
		# print(getGCD(gcd,y))

		gcd = getGCD(gcd,y)
	
	return gcd

#print(getGCD_List([100,20,60,30]))

# 	gcdVal = 1
# 	for i in range(1, max(numList) + 1) :
# 		if i > min(numList) :
# 			# 最小値を超えたら終わり
# 			break


# 		calcList = list(map(lambda x: x % i, numList))

# 		filterdList = list(filter(lambda x: x == 0, calcList))

# 		if len(filterdList) == len(numList):
# 			gcdVal = i
		
# 	return gcdVal


# 1つずつ要素を削りながら最大公約数を検索
maxGCD = 0
for i in range(n):
	tempList = aList.copy()
	# print(i)
	# #print(aList)
	# print(tempList.pop(i))
	# print(tempList)
	# print("---")
	# print(gcd_list(tempList))

	tempList.pop(i)
	gcdNum = getGCD_List(tempList)
	if gcdNum > maxGCD:
		maxGCD = gcdNum

print(maxGCD)

Submission status: Time Limit Exceeded

Solution code:
#import math
#from fractions import gcd
import fractions
from functools import reduce

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

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

gcdOrg = gcd(nums)
gcdMax = gcdOrg

for i in range(n):
    tempList = list(nums)
    del tempList[i]

    #temp = gcd(filter(index == i, nums))
    temp = gcd(tempList)

    if temp > gcdMax:
        gcdMax = temp

#print(gcdOrg)
print(gcdMax)