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:
# -*- coding: utf-8 -*-
import copy

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


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


left = []
right = []
for i in range(N):
    if i == 0:
        left.append(A[0])
        right.append(A[-1])
        continue

    left.append(gcd(left[i-1], A[i]))
    right.insert(0, gcd(right[0], A[N-i-1]))

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

print(max(gcd_list))

Submission status: Wrong Answer

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

C = 0
div_w = 0

for i in range(min(A)):
    C = 0
    if min(A)%(i+1) == 0:
        div_w = int(min(A)/(i+1))
        for j in A:
            if j % div_w != 0:
                C = C + 1
                if C >= 2:
                    break
        else:
            print(div_w)
            break

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

ans = A[0]

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(fractions.gcd, A_i))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

ans = 0

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(fractions.gcd, A_i))

print(ans)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    divisors = []

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

    divisors.sort(reverse=True)
    return divisors


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

ans = 1
divisors = make_divisors(A[0]) + make_divisors(A[1])
divisors = sorted(set(divisors), key=divisors.index)

for divisor in divisors:
    indivisible_count = 0
    for i in range(N):
        if A[i] % divisor != 0:
            indivisible_count += 1

    if indivisible_count <= 1:
        ans = divisor
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
try:
    from math import gcd
except:
    from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
AL = [0] * N  # 左からGCD
AR = [0] * N  # 右からGCD
for i in range(1, N):
    AR[i] = gcd(AR[i-1], A[i-1])
for i in range(N-1)[::-1]:
    AL[i] = gcd(AL[i], A[i+1])
A_list = [gcd(AL[i], AR[i]) for i in range(N)]
print(max(A_list))

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions

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

maxA = np.max(A)


if(maxA == np.min(A)):
    print(maxA)
elif(N==2):
    print(maxA)
else:
    R=np.zeros((N))
    L=np.zeros((N))
    M=np.zeros((N))

    L[0] = A[0]
    R[N-1] = A[N-1]
    for i in range(1,N):
        #0~i-1番目までの最大公約数
        L[i] = fractions.gcd(A[i-1],L[i-1])
        #i~N番
        R[N-1-i] = fractions.gcd(A[N-1-i],R[N-1-i+1])

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

    print("{}".format(int(np.max(M))))

Submission status: Wrong Answer

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

for i in range(min(A),1,-1):
    c = 0

    for j in A:
        if j % i != 0:
            c = c + 1
            if c >= 2:
                break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    RMQ　の実装
    '''

    def __init__(self, n, inf=float('inf')):
        '''
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.inf = inf
        self.data = [inf]*(2*self.n)

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n] = v

    def build(self):
        for k in reversed(range(self.n-1)):
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のminを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = gcd(ret, self.data[R-1])
            if L & 1:
                ret = gcd(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


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


N = int(input())
L = list(map(int, input().split()))
T = SegmentTree(N, 0)
for i, l in enumerate(L):
    T.set(i, l)
T.build()

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

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    RMQ　の実装
    '''

    def __init__(self, n, inf=float('inf')):
        '''
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.inf = inf
        self.data = [inf]*(2*self.n)

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n] = v

    def build(self):
        for k in reversed(range(self.n-1)):
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = gcd(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のminを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = gcd(ret, self.data[R-1])
            if L & 1:
                ret = gcd(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


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


N = int(input())
L = list(map(int, input().split()))
T = SegmentTree(N, 0)
for i, l in enumerate(L):
    T.set(i, l)
T.build()

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    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)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

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

print(max(T))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    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)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

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

print(T)

Submission status: Wrong Answer

Solution code:
import sys
N = input()

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


if len(A) < 3:
    print(max(A))
    sys.exit()



min_0 = A[0]
min_1 = A[1]
min_2 = A[2]


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

    min_num = min(x, y)
    max_num = max(x, y)
    dif = max_num - min_num
    return gcd(min_num, dif)

def check(n):
    fail_count = 0
    for a in A:
        if a % n != 0:
            fail_count +=1
            if fail_count == 2:
                return False
    return True




kouyaku_01 = gcd(min_0, min_1)
kouyaku_12 = gcd(min_1, min_2)
kouyaku_02 = gcd(min_0, min_2)


ans = 1
if check(kouyaku_01):
    ans = max(ans, kouyaku_01)

if check(kouyaku_12):
    ans = max(ans, kouyaku_12)


if check(kouyaku_02):
    ans = max(ans, kouyaku_02)


print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a<=b:
    a,b=b,a
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
L,R=[],[]
ld,rd=A[0],A[n-1]
for i in range(n):
  ld=gcd(ld,A[i])
  rd=gcd(rd,A[n-1-i])
  L.append(ld)
  R.append(rd)
ans=max(L[-2],R[1])
for i in range(1,n-1):
  ans=max(ans,gcd(L[i-1],R[n-i-2]))
print(ans if n!=2 else max(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
L = [0 for _ in range(N + 1)]
R = [0 for _ in range(N + 1)]

def sinGCD(a, b):
    if b == 0:
        return a

    # 再帰
    return sinGCD(b, a % b)

def listGCD(listA):
    lenList = len(listA)
    ans = 0
    for i in range(1, lenList):
        ans = max(ans, sinGCD(L[i - 1], R[i]))
    return ans

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

print(listGCD(A))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a<=b:
    a,b=b,a
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
L,R=[],[]
ld,rd=A[0],A[n-1]
for i in range(n):
  ld=gcd(ld,A[i])
  rd=gcd(rd,A[n-1-i])
  L.append(ld)
  R.append(rd)
ans=max(L[-2],R[1])
for i in range(1,n-1):
  ans=max(ans,gcd(L[i-1],R[n-i-2]))
print(ans)

Submission status: Wrong Answer

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

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

res = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if j-1 == i:
            B = [A[j],A[j-2]]
        else:
            B = [A[j],A[j-1]]
        res = max(res,gcd(max(B),min(B)))
    print(B)
    print(res)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    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)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

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

Submission status: Wrong Answer

Solution code:
import math

def sieve(n): 
  prime = [True for i in range(n+1)]
  p = 2
  while (p * p <= n):
    if (prime[p] == True):
      for i in range(p * 2, n+1, p):
        prime[i] = False
    p += 1

  prime_seq = []
  for p in range(2, n): 
    if prime[p]: 
      prime_seq.append(p)
  return prime_seq

def make_divisors(n, seq=None):
  # O(N**0.5)
  divisors = []
  for i in seq:
  #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

def main():
  N = int(input().strip())
  A = map(int, input().strip().split())
  divs_dict = dict()
  seq = sieve(int(1e5))
  seq.insert(0, 1)
  for a in A:
    divs = make_divisors(a, seq)
    for d in divs:
      if d in divs_dict.keys():
        divs_dict[d] += 1
      else:
        divs_dict[d] = 1
  
  result_divs = []
  for k in divs_dict.keys():
    if divs_dict[k] >= N-1:
      result_divs.append(k)
  print(sorted(result_divs)[-1])

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
X = [0 for i in range(n)]
Y = [0 for i in range(n)]
for i in range(1,n):
    X[i] = gcd(X[i-1],A[i-1])
for i in range(n-1)[::-1]:
    Y[i] = gcd(Y[i+1],A[i+1])
print(X)
print(Y)
Z = [gcd(X[i],Y[i]) for i in range(n)]
print(max(Z))

Submission status: Wrong Answer

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

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

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

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

result = max(L[1],L[-2])

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
N =  int(input())
A =  list(map(int, (input().split(' '))))
A =  list(range(1, 10**5))

from itertools import accumulate

gcds = []
left_all_gcd = list(accumulate(A, gcd))
right_all_gcd = list(accumulate(A[::-1], gcd))
for i in range(len(A)):
    if i == 0:
        gcds.append(right_all_gcd[-2])
    if i == len(A)-1:
        gcds.append(left_all_gcd[-2])
    else:
        hoge = [left_all_gcd[i-1]] + [right_all_gcd[-i]]
        gcds.append(gcd(left_all_gcd[i-1], right_all_gcd[-i]))

print(max(gcds))

Submission status: Wrong Answer

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


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

left = A.copy()
right = A.copy()

for i in range(1, N):
    left[i] = gcd(left[i-1], left[i])

for i in reversed(range(0, N-1)):
    right[i] = gcd(right[i+1], right[i])

print((left, right))

ans = max(right[1], left[-2])

for i in range(1, N-1):
    ans = max(ans, gcd(left[i-1], right[i+1]))

print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate

gcds = []
all_gcd = list(accumulate(A, gcd))
for i in range(len(A)):
    if i == 0:
        hoge = A[i+1:]
    hoge = [all_gcd[i-1]] + A[i+1:]
    gcds.append(reduce(gcd, hoge))

print(max(gcds))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def main():
    n = int(input())
    a = list(map(int, input().split()))
    left = [0]
    right = [0]
    m = 0
    for i in range(1, n):
        left.append(gcd(a[i - 1], a[i]))
    for i in range(n - 1, -1, -1):
        right.append(gcd(a[i], a[i - 1]))
    right.reverse()
    for i in range(n):
        m = max(m, left[i], right[i])
    print(m)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

maxA = np.max(A)

if(maxA == np.min(A)):
    print(maxA)
else:
    for i in range(maxA//2,1,-1):
        #全てのAに対してiで割り切れるか＝最大公約数
        #iで割り切れた数＝len(A)-1なら，残りの数にiをかけて最大公約数に出来る．
        dA = (A % i)>0
        count = np.sum((A % i>0))
        if(count < 2):
            print(i)
            break

Submission status: Wrong Answer

Solution code:
import fractions

gcd = fractions.gcd
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
ryuho = 0

if n == 2:
  print(max(a[0],a[1]))
  exit()

ans = gcd(a[0],a[1])
ryuho = gcd(ans,a[2])

if ans < gcd(a[1],a[2]):
  ans = gcd(a[1],a[2])

if ans < gcd(a[0],a[2]):
  ans = gcd(a[0],a[2])

if n == 3:
  print(ans)
  exit()

for i in range(3,n):
  temp1 = gcd(ans,a[i])
  
  if temp1 > ryuho:
    ans = temp1
  else:
    ans = ryuho
    ryuho = temp1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
left = []
l = arr[0]
right = []
r = arr[-1]
ans = 0
left = [0 for _ in range(n)]
right =  [0 for _ in range(n)]

def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
for i in range(n-1):
    l = gcd(l,arr[i])
    left[i]= l
    r = gcd(r,arr[-(i+1)])
    right[-(i+1)] = r
for i in range(n-1):
    if i-1 <0:
        a = arr[-1]
    else:
        a = left[i-1]
    if i+1>n-1:
        b = arr[0]
    else:
        b = right[i+1]
    ans = max(gcd(a,b),ans)
# print(left)
# print(right)
if n == 2:
    print(max(arr))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
left = []
l = arr[0]
right = []
r = arr[-1]
ans = 0
left = [0 for _ in range(n)]
right =  [0 for _ in range(n)]


def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
for i in range(n-1):
    l = gcd(l,arr[i])
    left[i]= l
    r = gcd(r,arr[-(i+1)])
    right[-(i+1)] = r
for i in range(n-1):
    if i-1 <0:
        a = arr[-1]
    else:
        a = left[i-1]
    if i+1>n-1:
        b = arr[0]
    else:
        b = right[i+1]
    ans = max(gcd(a,b),ans)
# print(left)
# print(right)
if n == 2:
    print(gcd(arr[0],arr[1]))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
left = []
l = arr[0]
right = []
r = arr[-1]
ans = 0
left = [0 for _ in range(n)]
right =  [0 for _ in range(n)]


def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
for i in range(n-1):
    l = gcd(l,arr[i])
    left[i]= l
    r = gcd(r,arr[-(i+1)])
    right[-(i+1)] = r
for i in range(n-1):
    if i-1 <0:
        a = arr[-1]
    else:
        a = left[i-1]
    if i+1>n-1:
        b = arr[0]
    else:
        b = right[i+1]
    ans = max(gcd(a,b),ans)
# print(left)
# print(right)
if n ==1:
    print(arr[0])
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
left = []
l = arr[0]
right = []
r = arr[-1]
ans = 0
left = [0 for _ in range(n)]
right =  [0 for _ in range(n)]


def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
for i in range(n-1):
    l = gcd(l,arr[i])
    left[i]= l
    r = gcd(r,arr[-(i+1)])
    right[-(i+1)] = r
for i in range(n-1):
    if i-1 <0:
        a = arr[-1]
    else:
        a = left[i-1]
    if i+1>n-1:
        b = arr[0]
    else:
        b = right[i+1]
    ans = max(gcd(a,b),ans)
# print(left)
# print(right)
print(ans)

Submission status: Wrong Answer

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

if n == 2:
    print(max(a[0], a[1]))
    import sys
    sys.exit()


tr = [a[n - 1]]
for i in range(1, n):
    tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()
ans = 1
for i in range(n):
    tmp = 1
    if i == 0: tmp = tr[i + 1]
    elif i == n - 1: tl[i - 1]
    else: tmp = gcd(tl[i - 1], tr[i + 1])
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

Submission status: Wrong Answer

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


tr = [a[n - 1]]
for i in range(1, n):
    tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()
ans = 1
for i in range(n):
    tmp = 1
    if i == 0: tmp = tr[i + 1]
    elif i == n - 1: tl[i - 1]
    else:tmp = gcd(tl[i - 1], tr[i + 1])
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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


tr = [a[n - 1]]
for i in range(1, n):
    tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()
ans = 1
print(tl,tr)
for i in range(n):
    tmp = 1
    if i == 0: tmp = tr[i + 1]
    elif i == n - 1: tl[i - 1]
    else:tmp = gcd(tl[i - 1], tr[i + 1])
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

L = [0]
R = [0]

for i in range(n):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[n-1-i]))
R.reverse()

result = []

for i in range(n-1):
    result.append(gcd(L[i], R[i+1])) 

print(max(result))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [x for x in map(int,input().split(" "))]

def gcd(m,n):
    if m == 0:
        return n
    while n != 0:
        a = n
        n = m % n
        m = a
    return m

l = [x for x in range(N)]
r = [x for x in range(N)]

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [x for x in map(int,input().split(" "))]

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

l = [x for x in range(N)]
r = [x for x in range(N)]

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = 1
k = []
g = []
l = []
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

x = gcd(A[0], A[1])
k.append(x)
for i in range(2, N):
    x = gcd(x, A[i])
    k.append(x)
    
g.append([0, 1])
for i in range(N-2):
    if k[i] != k[i+1]:
            g.append([i, i+1])
    else:
        if len(g) < 1:
            continue

#if len(g) <= 0:
#    print(max(k))
#    exit()

index1 = g[len(g)-1][0]
index2 = g[len(g)-1][1]
temp = A[index1]

B = max(k)
for i in range(N):
    if A[index1] != A[i]:
        B = A[i]
        break

A[index1] = B

x = gcd(A[0], A[1])
for i in range(2, N):
    x = gcd(x, A[i])

A[index1] = temp

for i in range(N):
    if A[index2] != A[i]:
        B = A[i]
        break

A[index2] = B

y = gcd(A[0], A[1])
for i in range(2, N):
    y = gcd(y, A[i])

print(max(x, y))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = 1
k = []
g = []
l = []
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

x = gcd(A[0], A[1])
k.append(x)
for i in range(2, N):
    x = gcd(x, A[i])
    k.append(x)
    
g.append([0, 1])
for i in range(N-2):
    if k[i] != k[i+1]:
            g.append([i, i+1])
    else:
        if len(g) < 1:
            continue

#if len(g) <= 0:
#    print(max(k))
#    exit()

index1 = g[len(g)-1][0]
index2 = g[len(g)-1][1]
temp = A[index1]

for i in range(N):
    if A[index1] != A[i]:
        B = A[i]
        break

A[index1] = B

x = gcd(A[0], A[1])
for i in range(2, N):
    x = gcd(x, A[i])

A[index1] = temp

for i in range(N):
    if A[index2] != A[i]:
        B = A[i]
        break

A[index2] = B

y = gcd(A[0], A[1])
for i in range(2, N):
    y = gcd(y, A[i])

print(max(x, y))

Submission status: Wrong Answer

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

for i in range(max(A),1,-1):
    c = 0

    for j in A:
        if j % i != 0:
            c = c + 1
            if c >= 2:
                break
    else:
        print(i)
        break

Submission status: Wrong Answer

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

A.sort(reverse = True)
w = 0
for i in range(1,A[0]):
    c = 0
    for j in A:
        if j % i != 0:
            c = c + 1
            if c >= 2:
                break
    else:
        w = i
print(w)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

L = [0]
R = [0]

for i in range(n):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[n-1-i]))
R.reverse()

print(max(gcd(l, r) for l, r in zip(L, R)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
if n==2:
    print(max(a[0],a[1]))
    exit()
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
gl = [0]*n
gl[0] = a[0]
gr = [0]*n
gr[-1] = a[-1]

for i in range(1,n):
    gl[i] = gcd(max(gl[i-1],a[i]),min(gl[i-1],a[i]))
for i in range(n-2,-1,-1):
    gr[i] = gcd(max(gr[i+1],a[i]),min(gr[i+1],a[i]))
ans = max(gl[1],gr[-2])
for i in range(1,n-1):
    g = gcd(max(gl[i-1],gr[i+1]),min(gl[i-1],gr[i+1]))
    ans = max(ans,g)
print(ans)

Submission status: Wrong Answer

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

A.sort(reverse = True)

for i in range(A[0],1,-1):
    c = 0

    for j in A:
        if j % i != 0:
            c = c + 1
            if c >= 2:
                break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
A = read_ints()

from fractions import gcd
# 累積GCDを使って解く
# 累積の概念は広く使えるxor,min,max,積等...
# 差ではなく左右から挟み込んで演算という概念をしっかりと身につけよう

left = []
right = []
tmp_fo = 0
tmp_re = 0
for fo, re in zip(A, A[::-1]):
    tmp_fo = gcd(tmp_fo, fo)
    tmp_re = gcd(tmp_re, re)
    left.append(tmp_fo)
    right.append(tmp_re)

right = right[::-1]

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

# ans = max(ans, right[1], left[-2])

print(ans)

Submission status: Wrong Answer

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

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

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

ans = 0
for i in range(N):
    ans = max(0, gcd(L[i], R[N-i]))

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    input = sys.stdin.readline
    try:
        n = int(input())
        A = list(map(int, input().split()))
        def gcd(a,b):
            while b:
                a,b=b,a%b
            return a
        from itertools import accumulate
        arrL = list(accumulate(A, gcd))
        arrR = list(accumulate(reversed(A), gcd))
        print(max(max(arrL[1:]) , max(arrR[1:]), gcd(arrL[0], arrR[0])))
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
n = int(input())
A = input().split()
B = sorted(list(set([int(a) for a in A])))
ans = 0
if len(B) <= 2:
    ans = max(B)
else:
    # B = list(set(m[:]))
    # B = sorted(B)
    # print(B)
    B = B[:3]
    gcm = gcd(B[0], B[1])
    if gcm > ans:
            ans = gcm
    gcm = gcd(B[1], B[2])
    if gcm > ans:
            ans = gcm
    gcm = gcd(B[0], B[2])
    if gcm > ans:
            ans = gcm
print(ans)

Submission status: Wrong Answer

Solution code:

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
n = int(input())
A = input().split()
B = sorted(list(set([int(a) for a in A])))
print(B)
ans = 0
if len(B) <= 2:
    ans = max(B)
else:
    # B = list(set(m[:]))
    # B = sorted(B)
    # print(B)
    B = B[:3]
    gcm = gcd(B[0], B[1])
    if gcm > ans:
            ans = gcm
    gcm = gcd(B[1], B[2])
    if gcm > ans:
            ans = gcm
    gcm = gcd(B[0], B[2])
    if gcm > ans:
            ans = gcm
print(ans)

Submission status: Wrong Answer

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

A.sort()

for i in range(A[1],1,-1):
    l = list(map(lambda x: x % i,A))
    if l.count(0) >= len(A)-1:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import itertools

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

def factorize(x, divisors=None):
    """xの素因数分解を表す辞書 {素因数: 指数}"""
    limitedDivisors = (divisors == None)
    if divisors == None:
        divisors = itertools.chain([2], range(3, 10 ** 9, 2))

    f = {}
    for d in divisors:
        c = 0
        while x % d == 0:
            c += 1
            x //= d
        if c > 0:
            f[d] = c
        if d * d > x > d:
            if limitedDivisors:
                f[x] = 1
            break
    return f

def dropmin(ls):
    """[min(ls[:i] + ls[i + 1:]) for i in range(len(ls))]"""
    # l = [min(ls[:i]) for i in range(len(ls))]
    l = [float('inf')] * N
    for i in range(1, N):
        l[i] = min(l[i - 1], ls[i - 1])
    # r = [min(ls[i + 1:]) for i in range(len(ls))]
    r = [float('inf')] * N
    for i in range(N - 2, -1, -1):
        r[i] = min(r[i + 1], ls[i + 1])
    return [min(a, b) for a, b in zip(l, r)]

def prod(ls):
    p = 1
    for x in ls:
        p *= x
    return p

# 各A_iの素因数
A = list(A)
F = [factorize(a) for a in A[:2]]

# 素因数の集合 (2要素に出現しない素因数は無視)
D =  set(F[0].keys())
D.update(F[1].keys())

E = set()
for d in D:
    c = 0
    for a in A:
        if a % d != 0:
            c += 1
            if c >= 2:
                E.add(d)
                break
D -= E

# 各A_iの素因数
F = [factorize(a, divisors=D) for a in A]

# Dの要素 d -> i -> dがA_iに含まれる個数
X = {d: [f[d] if d in f else 0 for f in F] for d in D}

# Dの要素 d → A_iを削除したときのdの個数の最小値のリスト
X = {d: dropmin(X[d]) for d in D}

S = [prod(d ** X[d][i] for d in D) for i in range(N)]
print(max(S))