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:
size=input()
size=int(size)
A=input().split()
GCD=1
for i in range(0,size):
    for j in range(1,size):
        a=int(A[i])
        b=int(A[j])
        if (i==j):
            continue
        candidate=1
        for k in range(1,max(a,b)):
            if(a%k==0 and b%k==0):
                candidate=candidate*k
                a=a/k
                b=b/k
        if (candidate>GCD):
            GCD=candidate

print(GCD)

Submission status: Time Limit Exceeded

Solution code:
size=input()
size=int(size)
A=input().split()
GCD=1
for i in range(0,size):
    for j in range(1,size):
        a=int(A[i])
        b=int(A[j])
        if (i==j):
            continue
        candidate=1
        for k in range(1,max(a,b)):
            if(a%k==0 and b%k==0):
                candidate=k
        if (candidate>GCD):
            GCD=candidate

print(GCD)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
inp_ints = list(map(int, input().split()))
# ints = list(set(inp_ints))

uniq_ints = list(set(inp_ints))
ints = uniq_ints
for m in uniq_ints:
    if inp_ints.count(m) >= 2:
        ints.append(m)

gcd = 0
result = 1
for i in range(len(ints)):
    gcd = 0
    for m in ints[:i]:
        gcd = fractions.gcd(gcd, m)
    for m in ints[i+1:]:
        gcd = fractions.gcd(gcd, m)
    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
inp_ints = list(map(int, input().split()))
uniq_ints = list(set(inp_ints))

ints = uniq_ints
for m in uniq_ints:
    if inp_ints.count(m) >= 2:
        ints.append(m)

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])
    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
ints = list(map(int, input().split()))
# ints.sort(reverse=True)

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])

    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
ints = list(map(int, input().split()))
ints.sort(reverse=True)

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])

    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
ints = list(map(int, input().split()))
ints.sort()

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])
        if gcd == 1:
            break
    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

gcd = 0
result = 1
holed_ints = []
for i in range(len(ints)):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(len(holed_ints)):
        gcd = fractions.gcd(gcd, holed_ints[j])
    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
ints = list(map(int, input().split()))
ints.sort(reverse=True)

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])
        if gcd == 1:
            break
    if gcd > result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
def gcd_seq(seq):
    from fractions import gcd
    size = len(seq)
    if size == 1:
        return seq[0]
    if size == 2:
        return gcd(seq[0], seq[1])
    ans = gcd(seq[0], seq[1])
    for i in range(2, size):
        ans = gcd(seq[i], ans)
    return ans


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

ANS = gcd_seq(A)  # no change
for i in range(N):
    a = A[:]
    a.pop(i)
    ANS = max((gcd_seq(a), ANS))
print(ANS)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if a%b==0 : return b
    else :
        while a%b != 0 :
            c = a%b 
            a = b 
            b = c 
        else : return c 

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

para_val_1= [i for i in range(n)]
count = []

if n > 2 :

    for i in range(n):
        para_val_1[i] = para_val[:]
        para_val_1[i][i] = 0
        para_val_1[i].sort()
        d = gcd(para_val_1[i][1],para_val_1[i][2])
        if n > 3 :
            for j in range(n-3):
                d = gcd(d,para_val_1[i][j+3])
            
        count.append(d)
    
     
else : 
    d = max(para_val[0],para_val[1])
    count.append(d)


answer = max(count)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
b = gcd(a[0], a[1])
c = [a[0], a[1]]
for i in range(2, n):
    g1 = gcd(b, a[i])
    d = []
    for j in c:
        g2 = gcd(j, a[i])
        if g2 > 1:
            d.append(g2)
    c = d
    if b > 1:
        c.append(b)
    b = g1

if c:
    print(max(c))
else:
    print(1)

Submission status: Time Limit Exceeded

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)

n = ip()                                     #入力整数1つ
#a,b,t= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#v=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
if n==2:
    print(max(a))
else:
    ans = []
    s = [a[0]]
    for i in range(1,n):
        s.append(fractions.gcd(s[i-1],a[i]))
    r = [a[n-1]]
    for i in range(n-2,-1,-1):
        r.insert(0,fractions.gcd(r[0],a[i]))
 #   print(s,"from left")
 #   print(r,"from right")
    ans.append(r[1])
    for i in range(1,n-1):
        ans.append(fractions.gcd(s[i-1],r[i+1]))
    ans.append(s[n-2])
    print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import copy

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

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

gcd_list = []
B_list = copy.deepcopy(A_list)
for i in range(N):
  B_list.pop(i)
  gcd_list.append(gcd(B_list))
  B_list = copy.deepcopy(A_list)
  
print(max(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
# Aiを消した最大公約数Miを求めて、最大のものを出力

import fractions
from functools import reduce


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


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

M = []
for i in range(0, N):
    if i == 0:
        M.append(gcd_list(A[1:N]))
    elif i == N - 1:
        M.append(gcd_list(A[0:N - 1]))
    else:
        M.append(fractions.gcd(gcd_list(A[0:i]), gcd_list(A[(i + 1):N])))

print(max(M))

Submission status: Time Limit Exceeded

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

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = [max(L_gcd[-2],R_gcd[1])]
for i in range(N-2):
    ans.append(gcd(L_gcd[i],R_gcd[i+2]))
print(max(ans))

Submission status: Time Limit Exceeded

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

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


def gcd_list(cur_gcd, numbers):
    res = cur_gcd
    for num in numbers:
        res = fractions.gcd(res, num)
    return res


max_gcd = max(As)
if N > 2:
    # i == 0
    # others = As[1:]
    max_gcd = gcd_list(max_gcd, As[1:])
    tmp_gcd = As[0]

    # i >= 1
    for i in range(1, N):
        # others = As[i + 1:]
        max_gcd = max(gcd_list(tmp_gcd, As[i + 1:]), max_gcd)
        tmp_gcd = fractions.gcd(tmp_gcd, As[i])

print(max_gcd)

Submission status: Time Limit Exceeded

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

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


def gcd_list(cur_gcd, numbers):
    res = cur_gcd
    for idx in range(len(numbers)):
        res = fractions.gcd(res, numbers[idx])
    return res


max_gcd = max(As)
if N > 2:
    # i == 0
    others = As[1:]
    max_gcd = gcd_list(max_gcd, others)
    tmp_gcd = As[0]

    # i >= 1
    for i in range(1, N):
        others = As[i + 1:]
        max_gcd = max(gcd_list(tmp_gcd, others), max_gcd)
        tmp_gcd = fractions.gcd(tmp_gcd, As[i])

print(max_gcd)

Submission status: Time Limit Exceeded

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

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = max(L_gcd[-2],R_gcd[1])

for i in range(N-2):
    if max(L_gcd[i],R_gcd[i+2])<=ans:
        break
    if gcd(L_gcd[i],R_gcd[i+2])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

Submission status: Time Limit Exceeded

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

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


def gcd_list(cur_gcd, numbers):
    res = cur_gcd
    for idx in range(len(numbers)):
        res = fractions.gcd(res, numbers[idx])
    return res


max_gcd = 0
if(N) == 2:
    max_gcd = max(As)
else:
    # i == 0
    others = [As[j] for j in range(1, N)]
    res = fractions.gcd(others[0], others[1])
    if len(others) > 2:
        res = gcd_list(res, As[2:])
    max_gcd = res
    tmp_gcd = As[0]

    # i >= 1
    for i in range(1, N):
        others = [As[j] for j in range(N) if j > i]
        max_gcd = max(gcd_list(tmp_gcd, others), max_gcd)
        tmp_gcd = fractions.gcd(tmp_gcd, As[i])

print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = list(map(int,input().split()))
max_a = max(a)
for i in range(max_a,0,-1):
    diff = [-1 if a[k]%i > 0 else 0 for k in range(len(a))]
    if sum(diff) == -1 or sum(diff) ==0:
        print(i)
        break

Submission status: Time Limit Exceeded

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

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


def gcd_list(numbers):
    res = fractions.gcd(numbers[0], numbers[1])
    if len(numbers) > 2:
        for idx in range(2, len(numbers)):
            res = fractions.gcd(res, numbers[idx])
    return res


max_gcd = 0
if(N) == 2:
    max_gcd = max(As)
else:
    for i in range(N):
        others = [As[j] for j in range(N) if j != i]
        max_gcd = max(gcd_list(others), max_gcd)

print(max_gcd)

Submission status: Time Limit Exceeded

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

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = max(L_gcd[-2],R_gcd[1])

for i in range(N-2):
    if max(L_gcd[i],R_gcd[i+2])<=ans:
        break
    if gcd(L_gcd[i],R_gcd[i+2])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

Submission status: Time Limit Exceeded

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

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = max(L_gcd[-2],R_gcd[1])

for i in range(N-2):
    if gcd(L_gcd[i],R_gcd[i+2])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

Submission status: Time Limit Exceeded

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

def saidai(A1,A2):
    minA = int(min(A1,A2))
    saidai = 1
    i = 2
    while(i <= minA // 2):
        if int(A1) % int(i) == 0 and int(A2) % int(i) == 0:
            saidai *= i
            A1 = int(A1) // int(i)
            A2 = int(A2) // int(i)
        else:
            i+=1
    return saidai

tmp = 1

for i in range(len(A)-1):
    for j in range(int(i)+1,len(A)):
        A1 = int(A[i])
        A2 = int(A[j])
        saidaiA = saidai(A1,A2)
        if saidaiA > tmp:
            tmp = saidaiA

print(tmp)

Submission status: Time Limit Exceeded

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

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(end_i, A):
    if(end_i == 0):
        return 0
    
    a = 0
    for i in range(end_i):
        a = gcd(a, A[i])
    return a


def R(start_i, A, N):
    if(start_i == N - 1):
        return 0

    a = 0
    for i in range(start_i + 1, N):
        a = gcd(a, A[i])
    return a


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

M = []
for i in range(N):
    M.append(gcd(L(i, A), R(i, A, N)))

print(max(M))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import copy
# Python 3.5 or later
import math
# Python 3.4 or earlier
import fractions

from functools import reduce

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

idata = [int(x) for x in data]

gcds = []
idata_temp = []

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

gcds.append(gcd_list(idata))

for i in range(len(idata) if len(idata) < 200 else 200):
    idata_temp = copy.copy(idata)
    idata_temp.pop(i)
    gcds.append(gcd_list(idata_temp))

print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import copy
# Python 3.5 or later
import math
# Python 3.4 or earlier
import fractions

from functools import reduce

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

idata = [int(x) for x in data]

gcds = []
idata_temp = []

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

gcds.append(gcd_list(idata))

for i in range(len(idata) if len(idata) < 10000 else 10000):
    idata_temp = copy.copy(idata)
    idata_temp.pop(i)
    gcds.append(gcd_list(idata_temp))

print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import copy
# Python 3.5 or later
import math
# Python 3.4 or earlier
import fractions

from functools import reduce

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

idata = [int(x) for x in data]

gcds = []
idata_temp = []

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

gcds.append(gcd_list(idata))

for i in range(len(idata)):
    idata_temp = copy.copy(idata)
    idata_temp.pop(i)
    gcds.append(gcd_list(idata_temp))

print(max(gcds))

Submission status: Time Limit Exceeded

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

import fractions
import copy
from functools import reduce

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

ans = 1
temp_A = A
for i in range(N):
    temp_A = copy.deepcopy(A)
    del temp_A[i]
    ans = max(ans, gcd_list(temp_A))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#最大公約数を求める関数gcd(x,y)
def gcd(x,y):
    a=max(x,y)
    b=min(x,y)
    while(a%b!=0):
        c=a%b
        a=b
        b=c
    return b

#N,Aの代入
N=int(input())
A_list=list(map(int,input().split()))

ans=0

#i番目の数字を消した場合の最大値を求める
for i in range(N):
    if i!=0:
        m=A_list[0]
    else:
        m=A_list[1]
        
    for j in range(N):
        if j==i:
            continue
        else:
            m=gcd(m,A_list[j])
    ans=max(ans,m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import functools
import math

n = int(input())
a = [int(i) for i in input().split()]
l = []
for i in range(n):
 b = a[i]
 del a[i]
 l.append(functools.reduce(gcd, a))
 a.insert(i,b)
print(max(l))

Submission status: Time Limit Exceeded

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


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


gcds = []
for i in range(N):
    m = A[0] if i != 0 else A[1]
    for j in range(N):
        if i == j:
            continue
        m = gcd(m, A[j])
    gcds.append(m)

max_gcd = 1
for i in range(N):
    max_gcd = max(max_gcd, max(gcd(A[i], gcds[i]), gcds[i]))

print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 3
    A = [1,1000000000,1000000000]

  AL = [0] * N    
  AR = [0] * N
  for i in range(N):
    if i != 0:
      AL[i] = functools.reduce(fractions.gcd, A[0:i+1])
    else:
      AL[i] = A[i]
    if i != N - 1:
      AR[i] = functools.reduce(fractions.gcd, A[i:])
    else:
      AR[i] = A[i]
      
  # print(AL)
  # print(AR)
  x = 0
  for i in range(N):
    if i == 0:
      tmp = AR[i+1]
    elif i == N - 1:
      tmp = AL[i-1]
    else:
      tmp = fractions.gcd(AL[i-1],AR[i+1])
    # print(tmp)
    if tmp > x: x = tmp
  
  print(x)
    
main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np
from copy import deepcopy
import math
import fractions
from functools import reduce

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

def power2_smaller(num):
    return len(str(bin(num))[2:])-1  
  
def power2_larger(num):
        return len(str(bin(num-1))[2:])

def gcd_each2(lst):
  if len(lst) == 1:
    return lst[0]
  new_lst = []
  for i in range(int(len(lst)/2)):
    new_lst.append(fractions.gcd(lst[2*i], lst[2*i+1]))
  if len(lst) % 2 == 1:
    new_lst.append(lst[-1])
  return gcd_each2(new_lst)


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

#import random
#N = 1000
#A = [random.randint(1,1e9) for i in range(N)]
#print(min(A))
               
solve = []
#nblock = int((len(A)-1+127)/128)
#for i in range(nblock):
  
for i in range(len(A)):
  lst = deepcopy(A)
  lst.pop(i)   
  
  #var = gcd_list(lst)
  var = gcd_each2(lst)
  solve.append(var)

ans = max(solve)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np
from copy import deepcopy
import math
import fractions
from functools import reduce

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

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

solve = []
for i in range(len(A)):
  lst = deepcopy(A)
  lst.pop(i)
  var = gcd_list(lst)
  solve.append(var)

ans = max(solve)
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!=0):
    a,b=b,a%b
  return a

cogcd=[0 for i in range(N)]
allgcd=GCD(A[0],A[1])
cogcd[0]=A[1]
cogcd[1]=A[0]

for i in range(2,N):
  for j in range(i):
    cogcd[j]=GCD(cogcd[j],A[i])
  cogcd[i]=allgcd
  allgcd=GCD(allgcd,A[i])
print(max(cogcd))

Submission status: Time Limit Exceeded

Solution code:
import functools as ft

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

def GCD(a,b):
  if(a<b): a,b=b,a
  while(b!=0):
    a,b=b,a%b
  return a

cogcd=[0 for i in range(N)]
for i in range(N):
  cogcd[i]=ft.reduce(GCD, A[:i]+A[i+1:])
print(max(cogcd))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from  functools import  reduce

n = int(input())
li = list(map(int,input().split()))
kotae = 1

for i in range(n):
	lis = li[:i]+li[i+1:]
	g = reduce(fractions.gcd,lis)
	kotae = max(kotae,g)
	
print(kotae)

Submission status: Time Limit Exceeded

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

#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


def gcd_multi(n,x):
    if n==1:
        return x[0]
    else:
        element = gcd(x[0], x[1])
        if n==2:
            return element
        else:
            for i in range(2,n):
                element=gcd(element,x[i])
            return element

ans = []
for i in range(n):
    l = copy.deepcopy(x)
    del l[i]
    ans.append(gcd_multi(n-1,l))

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcdaaaaaaaaa(L):
    nextminb = L[0]
    nextn = len(L)
    while True:
        n = nextn
        minb = nextminb
        for l in L[:n]:
            nextn = 0
            r= l % minb
            
            if r != 0:
                L[nextn] = r
                nextn += 1
                if r < nextminb :
                    nextminb = r
        if minb == nextminb:
            return minb
        
def gcd(a,b):
    if b == 0:
        return a
    else:
        r = a % b
        a = b
        b = r
        return gcd(a,b)
def gcdL(L):
    g = L[0]
    if len(L) > 1:
        for l in L[1:]:
            g = gcd(g,l)
    return g



lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcdL(A[0:i+1])
    rgcd[i] = gcdL(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd(lgcd[i-1],rgcd[i+1])
    if maxg < g:
        maxg = g

print(maxg)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
ans = 1
if len(a) == 2:
  print(max(a))
else:
  for i in range(n):
    b = copy.deepcopy(a)
    b.pop(i)
    b.sort
    b0 = b[0]
    for j in range(1,n-1):
      b1 = b[j]
      r = 0
      while True:
        r = b1 % b0
        if r == 0:
          break
        elif r > b0:
          b1, b0 = r, b0
        else:
          b1, b0 = b0, r
    if b0 > ans:
      ans = b0
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

    # divisors.sort()
    return divisors

list = []
for i in a:
    list.extend(make_divisors(i))

c = collections.Counter(list)
values, counts = zip(*c.most_common())

first = []
second = []
for value, count in zip(values,counts):
    if count == n:
        first.append(value)
    if count == n-1:
        second.append(value)
    if count < n-1:
        break

if len(second) == 0:
    print(max(first))

elif max(first) > max(second):
    print(max(first))

else:
    print(max(second))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

    # divisors.sort()
    return divisors

list = []
for i in a:
    list.extend(make_divisors(i))

c = collections.Counter(list)
values, counts = zip(*c.most_common())

first = []
second = []
for value, count in zip(values,counts):
    if count == n:
        first.append(value)
    if count == n-1:
        second.append(value)

if len(second) == 0:
    print(max(first))

elif max(first) > max(second):
    print(max(first))

else:
    print(max(second))

Submission status: Time Limit Exceeded

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split(" ")))#0~n-1
m=[]
def lgcd(x):
  if x!=0:
    b=a[0]
    for j in range(1,x):
      b=fractions.gcd(a[j],b)
    return b
  else:
    return 0
def rgcd(x):
  if x!=n:
    c=a[x]
    for j in range(x+1,n):
      c=fractions.gcd(a[j],c)
    return c
  else:
    return 0
for i in range(n):#0~n-1
  m.append(fractions.gcd(lgcd(i),rgcd(i+1)))
print(max(m))

Submission status: Time Limit Exceeded

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

left = [a[0]]
for i in range(1, n):
    left.append(fractions.gcd(left[len(left) - 1], a[i]))

right = [a[n - 1]]
for i in range(1, n):
    right.insert(0, fractions.gcd(right[0], a[n - i - 1]))

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

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(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)

    return divisors

ans = 1
dict = {i : 0 for i in make_divisors(A[0])}
for a in A[1:]:
    for i in dict.keys():
        if a % i == 0:
            dict[i] += 1
dict = sorted(dict.items(), key = lambda x:-x[0])
for k, v in dict:
    if v == N - 1 or v == N - 2:
        ans = max(ans, k)
        break

dict = {i : 0 for i in make_divisors(A[1])}
for a in [A[0]] + A[2:]:
    for i in dict.keys():
        if a % i == 0:
            dict[i] += 1
dict = sorted(dict.items(), key = lambda x:-x[0])
for k, v in dict:
    if v == N - 1 or v == N - 2:
        ans = max(ans, k)
        break
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)
s = set([])
def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            s.add(i)
            s.add(n // i)

for i in range(2):
    divisor(A[i])

for num in A:
    for key in s:
        if num % key == 0:
            d[key] += 1

ans = 1
for key, val in d.items():
    if val >= N - 1:
        ans = max(ans, key)

print(ans)

Submission status: Time Limit Exceeded

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

d = {}
s = set([])
def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            s.add(i)
            s.add(n // i)

for i in range(2):
    divisor(A[i])

for num in A:
    for key in s:
        if num % key == 0:
            if key not in d:
                d[key] = 1
            else:
                d[key] += 1

ans = 1
for key, val in d.items():
    if val >= N - 1:
        ans = max(ans, key)

print(ans)

Submission status: Time Limit Exceeded

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

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
for a in A:
    for i in make_divisors(a):
        if not i in dict:
            dict[i] = 0
        dict[i] += 1
dict = sorted(dict.items(), key = lambda x:-x[0])

f = False
for k, v in dict:
    if v == N or v == N - 1:
        print(k)
        break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(L):
    nextminb = L[0]
    while True:
        #print(L)
        minb = nextminb
        for i in range(len(L)):
            r = L[i] % minb
            if r != 0:
                L[i] = r
                if r < nextminb :
                    nextminb = r
        if minb == nextminb:
            return minb


lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcd(A[0:i+1])
    rgcd[i] = gcd(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd([lgcd[i-1],rgcd[i+1]])
    if maxg < g:
        maxg = g

print(maxg)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(L):
    while True:
        NL = []
        #print(L)
        minb = L[0]
        for l in L:
            r = l % minb
            if r != 0:
                NL.append(r)
        if(len(NL) == 0):
            return minb
        NL.append(minb)
        L = NL

lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcd(A[0:i+1])
    rgcd[i] = gcd(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd([lgcd[i-1],rgcd[i+1]])
    if maxg < g:
        maxg = g

print(maxg)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(L):
    while True:
        NL = []
        #print(L)
        minb = min(L)
        for l in L:
            r = l % minb
            if r != 0:
                NL.append(r)
        if(len(NL) == 0):
            return minb
        NL.append(minb)
        L = NL

lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcd(A[0:i+1])
    rgcd[i] = gcd(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd([lgcd[i-1],rgcd[i+1]])
    if maxg < g:
        maxg = g

print(maxg)