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: Wrong Answer

Solution code:
N = int(input())
As = [int(s) for s in input().split(' ')]
As.sort()
As = list(set(As))
A_max = max(As)

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

ret = 1
if len(As) == 1:
    ret = As[0]
elif len(As) == 2:
    # A1 A2
    ret = gcd(As[0], As[1])
elif len(As) == 3:
    # A1 A2 A3
    ret = max(gcd(As[0], As[1]), gcd(As[0], As[2]),gcd(As[1], As[2]))
else:
    # A1 A2 ... An-1 An
    ret1 = gcd(As[0], gcd(As[-2], As[-1]))
    ret2 = gcd(As[1], gcd(As[-2], As[-1]))
    
    ret = max(ret1, ret2)
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = [int(s) for s in input().split(' ')]
As.sort()
As = list(set(As))
A_max = max(As)

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

ret = 1
if len(As) == 1:
    ret = As[0]
elif len(As) == 2:
    # A1 A2
    ret = gcd(As[0], As[1])
elif len(As) == 3:
    # A1 A2 A3
    ret = max(gcd(As[0], As[1]), gcd(As[0], As[2]),gcd(As[1], As[2]))
else:
    # A1 A2 ... An-1 An
    ret1 = gcd(As[0], gcd(As[1], As[-2]))
    ret2 = gcd(As[0], gcd(As[1], As[-1]))
    ret3 = gcd(As[0], gcd(As[-2], As[-1]))
    ret4 = gcd(As[1], gcd(As[-2], As[-1]))
    
    ret = max(ret1, ret2, ret3, ret4)
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

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

gcds = set()
for i in range(N - 1):
    for j in range(i + 1, N):
        gcds.add(gcd(A[i], A[j]))

gcds = sorted(gcds)
print(gcds[1] if len(gcds) >= 2 else gcds[0])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100001)

# 一人消してgcd
n = int(input())
l = list(map(int, input().split(' ')))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)

memo = {}
mmm = int(1e10)
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm > current:
      mmm = current
    return current
  key = (i, skip, current)
  print(key)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]

print(max([ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]))

Submission status: Wrong Answer

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

min0=10**9+1
min1=10**9+1
for i in range(N):
    if min0>=A[i]:
        min1=min0
        min0=A[i]

if min0==min1==1:
    print(1)
    exit()
if N==2:
    print(max(A))
    exit()
yakusuu0lst=[]
yakusuu1lst=[]

if min0>1:
    for i in range(1,int(min0**0.5+1)):
        if min0%i==0:
            yakusuu0lst.append(i)
            yakusuu0lst.append(min0//i)
if min1>1:
    for i in range(1,int(min1**0.5+1)):
        if min1%i==0:
            yakusuu1lst.append(i)
            yakusuu1lst.append(min1//i)
yakusuu0count=[0 for i in range(len(yakusuu0lst))]
yakusuu1count=[0 for i in range(len(yakusuu1lst))]
length0=len(yakusuu0lst)
length1=len(yakusuu1lst)

for a in A:
    for i in range(length0):
        if a%yakusuu0lst[i]==0:yakusuu0count[i]+=1
    for i in range(length1):
        if a%yakusuu1lst[i]==0:yakusuu1count[i]+=1


div=1
for i in range(length0):
    if yakusuu0count[i]>=N-1 and div<yakusuu0lst[i]:
        div=yakusuu0lst[i]

for i in range(length1):
    if yakusuu1count[i]>=N-1 and div<yakusuu1lst[i]:
        div=yakusuu1lst[i]

print(div)

Submission status: Wrong Answer

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

min0=10**9+1
min1=10**9+1
for i in range(N):
    if min0>=A[i]:
        min1=min0
        min0=A[i]

if min0==min1==1:
    print(1)
    exit()
yakusuu0lst=[]
yakusuu1lst=[]

if min0>1:
    for i in range(1,int(min0**0.5+1)):
        if min0%i==0:
            yakusuu0lst.append(i)
            yakusuu0lst.append(min0//i)
if min1>1:
    for i in range(1,int(min1**0.5+1)):
        if min1%i==0:
            yakusuu1lst.append(i)
            yakusuu1lst.append(min1//i)
yakusuu0count=[0 for i in range(len(yakusuu0lst))]
yakusuu1count=[0 for i in range(len(yakusuu1lst))]
length0=len(yakusuu0lst)
length1=len(yakusuu1lst)

for a in A:
    for i in range(length0):
        if a%yakusuu0lst[i]==0:yakusuu0count[i]+=1
    for i in range(length1):
        if a%yakusuu1lst[i]==0:yakusuu1count[i]+=1


div=1
for i in range(length0):
    if yakusuu0count[i]>=N-1 and div<yakusuu0lst[i]:
        div=yakusuu0lst[i]

for i in range(length1):
    if yakusuu1count[i]>=N-1 and div<yakusuu1lst[i]:
        div=yakusuu1lst[i]

print(div)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
class SegmentTree:
    def segfunc(self,x,y):
        return gcd(x,y)

    def __init__(self,n,init,ide_ele):
        self.n = n
        self.ide_ele = ide_ele
        self.num = 2**(n-1).bit_length()
        self.seg = [ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1] = init[i]
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
    
    
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            lk = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])
    
    def query(self,p,q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p > 1:
            if p & 1 == 0:
                self.res = self.segfunc(res,self.seg[p])
            if q & 1 == 1:
                self.res = self.segfunc(res,self.seg[q])
                q -= 1
            p //= 2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

n = onem()

a = l()


ans = 0
p = SegmentTree(n,a,0)
for i in range(n):
    ans = max(ans,gcd(p.query(0,i),p.query(i+1,n)))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
l = list(map(int,input().split()))
if n == 2:
    print(max(l))
    exit()
l.sort()
ans = fractions.gcd(l[0],l[1])
for i in range(2,n):
    ans1 = fractions.gcd(ans,l[i])
    if ans1 < ans:
        if i != n-1 and l[i] != l[i+1]:
            print(ans)
            exit()
        else:
            print(ans1)
            exit()
print(max(fractions.gcd(l[0],l[-1]),fractions.gcd(l[1],l[-1])))

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
l = list(map(int,input().split()))
if n == 2:
    print(max(l))
    exit()
l.sort()
ans = fractions.gcd(l[0],l[1])
for i in range(2,n):
    ans1 = fractions.gcd(ans,l[i])
    if ans1 < ans:
        print(ans)
        exit()
print(max(fractions.gcd(l[0],l[-1]),fractions.gcd(l[1],l[-1])))

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
l = list(map(int,input().split()))
if n == 2:
    print(max(l))
    exit()
l.sort()
ans = fractions.gcd(l[0],l[1])
for i in range(2,n):
    ans1 = fractions.gcd(ans,l[i])
    if ans1 < ans:
        print(ans)
        exit()
print(max(fractions.gcd(l[0],l[2]),fractions.gcd(l[1],l[2])))

Submission status: Wrong Answer

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

import fractions

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

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

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

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x

N = int(input())
A = sorted(list(map(int,input().split())))
amin = A[0]
ind = 0
for i in range(1,N):
    a = gcd(amin,A[i])
    if a<amin:
        ind = i
        amin = a
if ind>1:
    A[ind] = A[0]
    a = A[0]
    for i in range(1,N):
        a = gcd(a,A[i])
else:
    B = A[:]
    B[0] = B[1]
    b0 = B[0]
    for i in range(1,N):
        b0 = gcd(b0,B[i])
    B = A[:]
    B[1] = B[0]
    b1 = B[0]
    for i in range(1,N):
        b1 = gcd(b1,B[i])
    a = max(b0,b1)
print(a)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x

N = int(input())
A = list(map(int,input().split()))
amin = A[0]
ind = 0
for i in range(1,N):
    a = gcd(amin,A[i])
    if a<amin:
        ind = i
        amin = a
if ind>1:
    A[ind] = A[0]
    a = A[0]
    for i in range(1,N):
        a = gcd(a,A[i])
else:
    B = A[:]
    B[0] = B[1]
    b0 = B[0]
    for i in range(1,N):
        b0 = gcd(b0,B[i])
    B = A[:]
    B[1] = B[0]
    b1 = B[0]
    for i in range(1,N):
        b1 = gcd(b1,B[i])
    a = max(b0,b1)
print(a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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

B = [0] * (N + 1)
B[0] = next(A)
B[1] = next(A)
B[2] = B[0]
B[0] = gcd(B[0], B[1])

for i, a in enumerate(A):
    i += 3
    B[i] = gcd(B[0], a)
    for j in range(i):
        B[j] = gcd(B[j], a)

print(max(B))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N):
    L[i+1] = gcd(L[i], A[i])
    R[N-i-1] = gcd(R[N-i], A[N-i-1])

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

Submission status: Wrong Answer

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

def segfunc(x,y):
    return math.gcd(x,y)

def init(init_val): #渡されたリストでsegを初期化
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x): #segの要素kをxに変更(セグ木全体の更新)
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q): #区間[p,q)での、segfuncに準じた値を返す
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
"""
最小値のセグ木 → 10**9　(最小値の更新に影響しないため)
　　和のセグ木 → 0　(上の単位元の説明を参照)
　　積のセグ木 → 1　(上の単位元の説明を参照)
　　gcdのセグ木 → 0　(gcdを更新しない値は0)
"""
ide_ele = 10**9

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num #単位元の配列(計算結果に影響を及ぼさない配列)を作成

init(lst1)
ans = 0
for i in range(n):
    #iをまたいでgcdをsearchしていくことで、iを任意の整数に変えたことになる
    ans = max(ans,math.gcd(query(0,i),query(i+1,n)))
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    tmp = gcd(a[i], a[j])
    if ans < tmp:
      ans = tmp
print(ans)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    tmp = gcd(a[i], a[j])
    if ans < tmp:
      ans = tmp
print(ans)

Submission status: Wrong Answer

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

import fractions
if N==2:
  print(max(A))
else:
  L=[0]*(N)
  R=[0]*(N)
  L[0]=A[0]
  R[N-1]=A[N-1]
  for i in range(1,N):
    L[i]=fractions.gcd(L[i-1],A[i])
  for i in range(1,N):
    R[N-1-i]=fractions.gcd(R[N-i],A[i])
  ans=0
  for i in range(1,N-1):
    x=fractions.gcd(L[i-1],R[i+1])
    ans=max(ans,x)

  print(max(ans,L[N-2],R[1]))

Submission status: Wrong Answer

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

import fractions
if N==2:
  print(max(A))
else:
  L=[0]*(N)
  R=[0]*(N)
  L[0]=A[0]
  R[N-1]=A[N-1]
  for i in range(1,N):
    L[i]=fractions.gcd(L[i-1],A[i])
  for i in range(1,N):
    R[N-1-i]=fractions.gcd(R[N-i],A[i])
  print(L)
  print(R)
  ans=0
  for i in range(1,N-1):
    x=fractions.gcd(L[i-1],R[i+1])
    ans=max(ans,x)

  print(max(ans,L[N-2],R[1]))

Submission status: Wrong Answer

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

import fractions
if N==2:
  print(max(A))
else:
  L=[0]*(N)
  R=[0]*(N)
  L[0]=A[0]
  R[N-1]=A[N-1]
  for i in range(1,N):
    L[i]=fractions.gcd(L[i-1],A[i])
  for i in range(1,N):
    R[N-1-i]=fractions.gcd(R[N-i],A[i])
  ans=0
  for i in range(1,N-1):
    x=fractions.gcd(L[i-1],R[i+1])
    ans=max(ans,x)

  ans=max(ans,L[N-2],R[1],)
  print(ans)

Submission status: Wrong Answer

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

import fractions

L=[0]*(N)
R=[0]*(N)
L[0]=A[0]
R[N-1]=A[N-1]
for i in range(1,N):
  L[i]=fractions.gcd(L[i-1],A[i])
for i in range(1,N):
  R[N-1-i]=fractions.gcd(R[N-i],A[i])
ans=0
for i in range(1,N-1):
  x=fractions.gcd(L[i-1],R[i+1])
  ans=max(ans,x)

ans=max(ans,L[N-2],R[1],R[0])
print(ans)

Submission status: Wrong Answer

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

import fractions

L=[0]*(N)
R=[0]*(N)
L[0]=A[0]
R[N-1]=A[N-1]
for i in range(1,N):
  L[i]=fractions.gcd(L[i-1],A[i])
for i in range(1,N):
  R[N-1-i]=fractions.gcd(R[N-i],A[i])
ans=0
for i in range(1,N-1):
  x=fractions.gcd(L[i-1],R[i+1])
  ans=max(ans,x)

ans=max(ans,L[N-2],R[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
M=[]
i=0
for i in range(N):
    L=0
    R=N-1
    l=1
    r=1
    n=True
    while n:
        if L==i and R==i:
            M.append(gcd(l,r))
            n=False
        elif L==i and R!=i:
            if R==N-1:
                r=A[R]
            else:
                r=gcd(r,A[R])
            R-=1
        elif L!=i and R==i:
            if L==0:
                l=A[L]
            else:
                l=gcd(l,A[L])
            L+=1
        else:
            if L==0 and R==N-1:
                l=A[L]
                r=A[R]
            else:
                l=gcd(l,A[L])
                r=gcd(r,A[R])
            R-=1
            L+=1
print(max(M))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
l1 = [0] * N
l2 = [0] * N
for i in range(N):
    l1[i] = gcd(l1[i-1], A[i-1])
for i in range(N)[::-1]:
    l2[i] = gcd(l2[i-1], A[i-1])
ans = 0
for i in range(N):
    ans = max(ans, gcd(l1[i], l2[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
A = A[:]
# print(A)
# exit()
l1, l2 = [0], [0]
for i in range(1, len(A)+1):
    l1.append(gcd(l1[i-1], A[i-1]))
    l2.append(gcd(l2[i-1], A[-i]))
l1.append(l1[-1])
l2.append(l2[-1])
# l2.reverse()
# l2.reverse()
# l1 = l1[1:]
# l2 = l2[:-1]
# print("l1", l1)
# print("l2", l2)
ll = []
ans = 0
for i in range(len(l1) - 2):
    # print(l1[i], l2[-i-1])
    ans = max(ans, gcd(l1[i], l2[i+2]))
    ans = max(ans, gcd(l2[i], l1[i+2]))
    ans = max(ans, gcd(l1[i], l2[i]))

print(ans)

Submission status: Wrong Answer

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

n=int(input())
a=list(map(int,input().split()))
a.append(a[-1])

ans=[]

gcd_left=[0]*n
gcd_right=[0]*n
for i in range(1,n):
    gcd_left[i]=gcd(gcd_left[i-1],a[i-1])
    gcd_right[n-i-1]=gcd(gcd_right[n-i],a[n-i])

print(gcd_left)
print(gcd_right)

ans=[]
for i in range(n):
    ans.append(gcd(gcd_left[i],gcd_right[i]))

print(max(ans))

Submission status: Wrong Answer

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

N = int(input())

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

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

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

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

challenge.extend(second_possible)

default.sort()
challenge.sort()

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

Submission status: Wrong Answer

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

N = int(input())

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

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

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

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

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

default.sort()
challenge.sort()

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

Submission status: Wrong Answer

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

n=int(input())
a=list(map(int,input().split()))
a.append(a[-1])

ans=[]

for i in range(n):
    temp1=0
    for j in range(i):
        temp1=gcd(temp1,a[j])
    temp2=a[i+1]
    for k in range(i+1,n):
        temp2=gcd(temp2,a[k])
    ans.append(gcd(temp1,temp2))

print(max(ans))

Submission status: Wrong Answer

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

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

ans=[]
for i in range(n-1):
    for j in range(i+1,n):
        g=gcd(a[i],a[j])
        ans.append(g)
ans=sorted(set(ans))

try:
    print(ans[1])
except:
    print(ans[0])

Submission status: Wrong Answer

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

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

temp=a[0]
ans=[1]
for i in range(1,n):
    g=gcd(a[i],temp)
    ans.append(g)
ans=sorted(ans)

print(ans[1])

Submission status: Wrong Answer

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

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

temp=a[0]
ans=[]
for i in range(1,n):
    g=gcd(a[i],temp)
    ans.append(g)
ans=sorted(ans)

try:
    print(ans[1])
except:
    print(ans[0])

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import itertools
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in itertools.combinations(A,2):
  ans = max(ans, reduce(gcd,i))
print(ans)

Submission status: Wrong Answer

Solution code:
def gcb(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

maxgcb = 0
for i in range(n):
    jsub = 0
    ksub = 0
    for j in range(i):
        if j == 0:
            jsub = a[j]
        else:
            jsub = gcb(sub,a[j])
    for k in range(i + 1,n):
        if k == 0:
            ksub = a[k]
        else:
            ksub = gcb(ksub,a[k])
    sub = gcb(jsub,ksub)
    if i == 0:
        maxgcb = sub
    else:
        maxgcb = max(maxgcb,sub)

print(maxgcb)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if N==2:ans=max(a)
else:
    lst = [gcd(a[0],a[N-1])]

    for i in range(0, N-1):
        lst.append(gcd(a[i], a[i+1]))
    lst.sort()
    ans = lst[2]
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def gc(a,b):
  if a==0 or b==0:
    return max(a,b)
  else:
    return gcd(a,b)
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]
lgcd=[0]
rgcd=[0]
for i in range(1,n):
  lgcd.append(gc(a[i],lgcd[-1]))
  rgcd.append(gc(a[-i-1],rgcd[-1]))
GCD=0
for i in range(n):
  GCD=max(GCD,gc(lgcd[i],rgcd[-i-1]))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]
lgcd=[0]
rgcd=[0]
for i in range(n-1):
  lgcd.append(gcd(a[i],lgcd[-1]))
  rgcd.append(gcd(a[-i-1],rgcd[-1]))
GCD=0
for i in range(n):
  GCD=max(GCD,gcd(lgcd[i],rgcd[-i-1]))
print(GCD)

Submission status: Wrong Answer

Solution code:
import functools, fractions

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

gcd_max = 0

for i in range(n):
  ad = a
  ad[i] = ad[i - 1]
  gcd = functools.reduce(fractions.gcd, ad)
  if gcd >= gcd_max:
    gcd_max = gcd

print(gcd_max)

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

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


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


n = int(input())
lst = list(set(map(int, input().split())))
if len(lst) == 1:
  max_gcd = lst[0]
else:
  min_v = min(lst)

  max_gcd = 0
  for i in range(n):
    arr = lst[:i] + lst[i + 1:len(lst)]
    if min_v < max_gcd:
      break
    wk_gcd = gcd(*arr)
    max_gcd = wk_gcd if wk_gcd > max_gcd else max_gcd

print(max_gcd)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
gcda = []
L = [0 for i in range(N)]
R = [0 for i in range(N)]
L[1] = A[0]
R[-2] = A[-1]
for i in range(1,N-1):
    L[i] = gcd(L[i-1],A[i])

for i in range(N-2,-1,-1):
    R[i] = gcd(R[i+1],A[i])
L[0] = R[0]
R[-1] = L[-1]
for i in range(N):
    x = gcd(L[i],R[i])
    gcda.append(x)
print(max(gcda))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
a.sort()
if len(a)==2:
    print(max(a[0],a[1]))
    exit()
ans=max(gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[2],a[0]))
for i in range(4,n):
    ans=gcd(ans,a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)==2:
    print(max(a[0],a[1]))
    exit()
ans=max(gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[2],a[0]))
for i in range(4,n):
    ans=gcd(ans,a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)==2:
    print(max(a[0],a[1]))
    exit()
ans=max(gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[2],a[0]))
for i in range(3,n):
    ans=gcd(ans,a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

n=int(input())
L=map(int,input().split())

ans=0
for i in list(itertools.permutations(L,2)):
      a,b=i[0],i[1]
      x=gcd(a,b)
      ans=max(ans,x)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as f

N = int(input())
A = [int(i) for i in input().split()]
L = [A[0]]
for i in range(1, N):
    L.append(f.gcd(L[-1], A[i]))
A.reverse()
R = [A[0]]
for i in range(1, N):
    R.append(f.gcd(R[-1], A[i]))
R.reverse()
ans = 0
for i in range(N):
    if i == 0:
        ans = max(ans, R[i + 1])
    elif i == N - 1:
        ans = max(ans, L[i])
    elif i + 2 <= N - 1:
        ans = max(ans, f.gcd(L[i], R[i + 2]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as f

N = int(input())
A = [int(i) for i in input().split()]
L = [A[0]]
for i in range(1, N):
    L.append(f.gcd(L[-1], A[i]))
A.reverse()
R = [A[0]]
for i in range(1, N):
    R.append(f.gcd(R[-1], A[i]))
R.reverse()
ans = 0
for i in range(N):
    if i + 2 <= N - 1:
        ans = max(ans, f.gcd(L[i], R[i + 2]))
    elif i == N - 1:
        ans = max(ans, L[i])
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(max(A))
    exit()

org_A=A[:]
#左から最大公約数作る右もね
A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0
for i in range(N-1):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    ans=max(ans,temp)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

N=int(input())
A=list(map(int,input().split()))
org_A=A[:]
#左から最大公約数作る右もね
A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0
for i in range(N-1):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    ans=max(ans,temp)

print(ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int,input().split()))
print("I didn't solve")

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(len(A)):
    for j in range(len(A)):
        if i!= j:
            ans = max(ans,gcd(A[i],A[j]))
print(ans)