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())
a=[int(i) for i in input().split()]
a.sort()

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

check=a[0]
for i in range(2,n):
    check=gcd(check,a[i])

check2=a[1]
for i in range(2,n):
    check2=gcd(check2,a[i])

if n==2:
    print(max(a))
else:
    print(max(check,check2))

Submission status: Wrong Answer

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

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

check=a[0]
for i in range(2,n):
    check=gcd(check,a[i])

check2=a[1]
for i in range(2,n):
    check2=gcd(check2,a[i])

if n==2:
    print(max(a))
else:
    print(max(check,check2))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

gcd_box=[]

for i in range(n-1):
    if i==0:
        # 左端を消す
        gcd_box.append(gcd_list(a[1:]))
        # 右端を消す
    elif i==n-1:
        gcd_box.append(gcd_list(a[:n]))
    else:
        L_gcd=gcd_list(a[:i])
        R_gcd=gcd_list(a[i+1:])

        gcd_box.append(fractions.gcd(L_gcd,R_gcd))


    
print(max(gcd_box))

Submission status: Wrong Answer

Solution code:
import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

res = 0
b = [0] * n
for i in range(n-1):
    b[i] = fractions.gcd(a[i],a[i+1])
b[n-1] = fractions.gcd(a[n-1], a[0])

c = [0] * n
for i in range(1,n):
    c[i] = b[i-1] + b[i]
c[0] = b[0] + b[n-1]

minindex = c.index(min(c))

aa = a[:minindex] + a[minindex + 1:]

print(functools.reduce(fractions.gcd,aa))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
array = list(map(int,input().split()))
gcd_arr = [array[0]]

for i in range(N-1):
  gcd_arr.append(gcd(gcd_arr[-1],array[i+1]))

gcd_arr.reverse()

new_gcd0 = array[0]
for j in range(N-2):
  new_gcd0 = gcd(new_gcd0,array[j+1])

new_gcd1 = array[1]
for k in range(N-2):
  new_gcd1 = gcd(new_gcd1,array[k+2])
  
num = array.pop(N-i-1)
new_gcd2 = array[0]
for i in range(N-2):
  new_gcd2 = gcd(new_gcd2,array[i+1])
  
print(max(new_gcd0,new_gcd1,new_gcd2))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
N=int(input())
A=list(map(int,input().split()))

def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)

def L(i):
  if i==0:
    return 0
  else:
    return gcd(L(i-1),A[i-2])

def R(i):
  if i==N+1:
    return 0
  else:
    return gcd(R(i+1),A[i-1])

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
#from math import gcd
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
ans = 0
tmp = A[0]
for i in range(1,N):
    tmp = gcd(A[i],tmp)
A = A//tmp
num = 0
numtmp = 10**10
hantei = False
judge = False
for i in range(N-1):
    tmp2 = gcd(A[i],A[i+1])
    if tmp2 == 1 and (i == 0 or i == N-2):
        num += 1
        numtmp = i
        hantei = True
        continue
    if tmp2 == 1 and judge == False:
        num += 1
        judge = True
        continue
    if tmp2 == 1 and judge == True:
        if num == 1:
            numtmp = i
        num += 1
        hantei = True
    judge = False
if hantei == True and num <= 2:
    ans = 0
    tmp3 = A[0]
    if numtmp == 0:
        tmp3 =A[1]
    for i in range(1,N):
        if i == numtmp:
            continue
        tmp3 = gcd(A[i],tmp3)
    print(tmp*tmp3)
else:
    print(tmp)

Submission status: Wrong Answer

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

import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd

left = [a[0]]
right = [a[-1]]

for i in range(1, n):
    left.append(gcd(left[i-1], a[i]))
    right.append(gcd(right[i-1], a[n-i-1]))

print(left, right)
ans = 0
for i in range(n):
    if i == 0:
        num = right[n-i-2]
    elif i == n - 1:
        num = left[i-1]
    else:
        num = gcd(left[i-1], right[n-i-2])
    if num > ans:
        ans = num

print(ans)

Submission status: Wrong Answer

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

import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd

left = [a[0]]
right = [a[-1]]

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

ans = 0
for i in range(n):
    if i == 0:
        num = right[i+1]
    elif i == n - 1:
        num = left[i-1]
    else:
        num = gcd(left[i-1], right[i+1])
    if num > ans:
        ans = num

print(ans)

Submission status: Wrong Answer

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

import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd

left = [a[0]]
right = [a[-1]]

for i in range(1, len(a)):
    left.append(gcd(left[i-1], a[i]))
    right.insert(0, gcd(right[i-1], a[len(a)-i-1]))

ans = 0
for i in range(n):
    if i == 0:
        num = right[i+1]
    elif i == n - 1:
        num = left[i-1]
    else:
        num = gcd(left[i-1], right[i+1])
    if num > ans:
        ans = num

print(ans)

Submission status: Wrong Answer

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

import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd

left = [a[0]]
right = [a[-1]]

for i in range(1, len(a)):
    left.append(gcd(left[i-1], a[i]))
    right.insert(0, gcd(right[i-1], a[len(a)-i-1]))

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

print(ans)

Submission status: Wrong Answer

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

import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd

left = [a[0]]
right = [a[-1]]

for i in range(1, len(a)):
    left.append(gcd(left[i-1], a[i]))
    right.insert(0, gcd(right[i-1], a[len(a)-i-1]))


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

print(max(ans))

Submission status: Wrong Answer

Solution code:
import copy
import fractions
 
n = int(input())
l = list(map(int, input().split()))
sum = 0
if len(l) == 2:
    print(max(l[0], l[1]))
    exit()
else:
    for i in range(n):
        ll = copy.deepcopy(l)
        ll.pop(i)
        ans = ll[0]
        for j in range(1, len(ll)):
            ans = fractions.gcd(ans, ll[j])
            if sum < ans:
                sum = ans
print(sum)

Submission status: Wrong Answer

Solution code:
import copy
import fractions

n = int(input())
l = list(map(int, input().split()))
sum = 0
if len(l) == 2:
    print(max(l[0], l[1]))
    exit()
    for i in range(n):
        ll = copy.deepcopy(l)
        ll.pop(i)
        ans = ll[0]
        for j in range(1, len(ll)):
            ans = fractions.gcd(ans, ll[j])
            if sum < ans:
                sum = ans
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
sum = 0
if len(l) == 2:
    print(max(l[0], l[1]))
    exit()
    for i in range(n):
        ll = copy.deepcopy(l)
        ll.pop(i)
        ans = ll[0]
        for j in range(1, len(ll)):
            ans = fractions.gcd(ans, ll[j])
            if sum < ans:
                sum = ans
print(sum)

Submission status: Wrong Answer

Solution code:
import fractions

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

minimum = 10 ** 10
minimum_index = 0

x = 0
for i in range(N):
    if i == N - 1:
        x = fractions.gcd(A[i], A[0])
    else:
        x = fractions.gcd(A[i], A[i + 1])
    if x < minimum:
        minimum = x
        minimum_index = i
  
gcd = 0      
for i in range(N):
    if i == minimum_index or i == minimum_index + 1:
        continue
    
    if gcd == 0:
        gcd = A[i]
    else:
        gcd = fractions.gcd(gcd, A[i])

x = fractions.gcd(gcd, A[minimum_index])
y = 0
if minimum_index != N - 1:
    y = fractions.gcd(gcd, A[minimum_index + 1])
else:
    y = fractions.gcd(gcd, A[0])

print(max(x, y))

Submission status: Wrong Answer

Solution code:
import fractions

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

minimum = 10 ** 10
minimum_index = 0


for i in range(N - 1):
    x = fractions.gcd(A[i], A[i + 1])
    if x < minimum:
        minimum = x
        minimum_index = i
  
gcd = 0      
for i in range(N - 1):
    if i == minimum_index or i == minimum_index + 1:
        continue
    
    if gcd == 0:
        gcd = A[i]
    else:
        gcd = fractions.gcd(gcd, A[i])

x = fractions.gcd(gcd, A[minimum_index])
y = fractions.gcd(gcd, A[minimum_index + 1])

print(max(x, y))

Submission status: Wrong Answer

Solution code:
import sys
import fractions
input = sys.stdin.readline
import heapq


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A_sorted = sorted(A)

    if len(A) == 2:
        print(max(A))
        exit()

    min = 10 ** 10
    min_index = -1
    for i in range(N - 1):
        x = fractions.gcd(A_sorted[i], A_sorted[i + 1])
        if min > x:
            min = x
            min_index = i

    gcd = A_sorted[0]
    if min_index == 0:
        gcd = A_sorted[2]

    for i in range(N):
        if i == min_index or i == min_index + 1:
            continue
        gcd = fractions.gcd(gcd, A_sorted[i])

    x = fractions.gcd(gcd, A_sorted[min_index])
    y = fractions.gcd(gcd, A_sorted[min_index + 1])

    print(max([x, y]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import fractions
input = sys.stdin.readline
import heapq


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A_sorted = sorted(A)

    if len(A) == 2:
        print(max(A))
        exit()

    h = []
    heapq.heappush(h, fractions.gcd(A_sorted[0], A_sorted[-1]))
    for i in range(N - 1):
        heapq.heappush(h, fractions.gcd(A_sorted[i], A_sorted[i + 1]))

    heapq.heappop(h)
    heapq.heappop(h)

    gcd = 0
    while len(h) > 0:
        x = heapq.heappop(h)
        gcd = fractions.gcd(x, gcd)

    print(gcd)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A_sorted = sorted(A)

    if len(A) == 2:
        print(max(A))
        exit()

    gcd1 = fractions.gcd(A_sorted[0], A_sorted[1])
    gcd2 = fractions.gcd(A_sorted[1], A_sorted[2])
    gcd3 = fractions.gcd(A_sorted[0], A_sorted[2])
    gcd4 = 0

    is_skipped = False
    is_second_skipped = False
    for i in range(3, N):
        tmp = fractions.gcd(gcd1, A[i])
        if is_skipped:
            gcd1 = tmp
            tmp2 = fractions.gcd(gcd4, A[i])
            if is_second_skipped:
                gcd4 = tmp2
            else:
                if tmp2 < gcd4:
                    is_second_skipped = True
        else:
            if tmp < gcd1:
                gcd4 = tmp
                is_skipped = True

        gcd2 = fractions.gcd(gcd2, A[i])
        gcd3 = fractions.gcd(gcd3, A[i])

    print(max([gcd1, gcd2, gcd3, gcd4]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A_sorted = sorted(A)

    if len(A) == 2:
        print(max(A))
        exit()

    gcd1 = fractions.gcd(A_sorted[0], A_sorted[1])
    gcd2 = fractions.gcd(A_sorted[1], A_sorted[2])
    gcd3 = fractions.gcd(A_sorted[0], A_sorted[2])
    gcd4 = 0

    is_skipped = False
    for i in range(3, N):
        tmp = fractions.gcd(gcd1, A[i])
        if is_skipped:
            gcd1 = tmp
            gcd4 = fractions.gcd(gcd4, A[i])
        else:
            if tmp < gcd1:
                gcd4 = tmp
                is_skipped = True

        gcd2 = fractions.gcd(gcd2, A[i])
        gcd3 = fractions.gcd(gcd3, A[i])

    print(max([gcd1, gcd2, gcd3, gcd4]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A_sorted = sorted(A)

    if len(A) == 2:
        print(max(A))
        exit()

    gcd1 = fractions.gcd(A_sorted[0], A_sorted[1])
    gcd2 = fractions.gcd(A_sorted[1], A_sorted[2])
    gcd3 = fractions.gcd(A_sorted[0], A_sorted[2])
    gcd4 = 0

    is_skipped = False
    for i in range(3, N):
        tmp = fractions.gcd(gcd1, A[i])
        if is_skipped:
            gcd1 = tmp
            gcd4 = fractions.gcd(gcd3, A[i])
        else:
            if tmp < gcd1:
                gcd4 = tmp
                is_skipped = True

        gcd2 = fractions.gcd(gcd2, A[i])
        gcd3 = fractions.gcd(gcd3, A[i])

    print(max([gcd1, gcd2, gcd3, gcd4]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import fractions
input = sys.stdin.readline
import heapq


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    h = []
    for a in A:
        heapq.heappush(h, -a)

    if len(A) == 2:
        print(max(A))
        exit()

    x = -heapq.heappop(h)
    y = -heapq.heappop(h)
    z = -heapq.heappop(h)

    xy = fractions.gcd(x, y)
    yz = fractions.gcd(y, z)
    xz = fractions.gcd(x, z)

    gcd = max([xy, yz, xz])

    while len(h) > 0:
        x = -heapq.heappop(h)
        gcd = fractions.gcd(gcd, x)

    print(gcd)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#配列の中で一つの要素だけを除いた最大公約数の中で最大のものを返す
def gcd_exclude_1(A,N):
    seki = 1
    A.sort()
    Max = A[N-1]

    for x in reversed(range(2,A[1]+1)):
        count = 0

        #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
        for y in reversed(range(2,N)):
            if A[y] % x != 0:
                break
        else:
            seki = x
            break

    return seki

def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    print(gcd_exclude_1(A,N))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#配列の中で一つの要素だけを除いた最大公約数の中で最大のものを返す
def gcd_exclude_1(A,N):
    seki = 1
    A.sort()
    Max = A[N-1]

    for x in reversed(range(2,int(Max**0.5)+1)):
        count = 0

        #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
        for y in range(N):
            if A[y] % x != 0:
                count += 1
            if count >= 2:
                break
        else:
            seki = x
            break

    for x in range(2,N):
        if A[x] % A[1] != 0:
            break
    else:
        seki = max(seki,A[1])

    return seki

def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    print(gcd_exclude_1(A,N))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#配列の中で一つの要素だけを除いた最大公約数の中で最大のものを返す
def gcd_exclude_1(A,N):
    seki = 1
    A.sort()
    Max = A[N-1]

    for x in reversed(range(2,int(Max**0.5)+1)):
        count = 0

        #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
        for y in range(N):
            if A[y] % x != 0:
                count += 1
            if count >= 2:
                break
        else:
            seki = x
            break

    for x in range(N):
        count = 0
        if A[x] % A[1] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = max(seki,A[1])

    return seki

def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    print(gcd_exclude_1(A,N))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

L = [0]
R = [0]

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

R = list(reversed(R))


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

ans = max(ans, R[1])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1
Max = max(A)

#配列の中で最も大きい要素の2乗根まで約数における走査
for x in range(2,int(Max**0.5)+1):
    count = 0

    #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

smallElement = 0

for i in range(N):
    count = 0
    if smallElement >= 2:
        break
    if A[i] < Max**0.5+1:
        smallElement += 1
        continue
    for j in range(N):
        if A[j] % A[i] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1
Max = max(A)

#配列の中で最も大きい要素の2乗根まで約数における走査
for x in range(2,int(Max**0.5)+1):
    count = 0

    #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

smallElement = 0

for i in range(N):
    count = 0
    if smallElement >= 2:
        break
    if A[i] < Max**0.5+1:
        smallElement += 1
    for j in range(N):
        if A[j] % A[i] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1
Max = max(A)

#配列の中で最も大きい要素の2乗根まで約数における走査
for x in range(2,int(Max**0.5)+1):
    count = 0

    #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

smallElement = 0

for i in range(N):
    count = 0
    if smallElement >= 2:
        break
    if A[i] < Max**0.5+1:
        smallElement += 1
    for j in range(N):
        if A[i] % A[j] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1
Max = max(A)

#配列の中で最も大きい要素の2乗根まで約数における走査
for x in range(2,int(Max**0.5)+1):
    count = 0

    #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

smallElement = 0

for i in range(N):
    count = 0
    if smallElement >= 2:
        break
    if A[i] < 1000000000**0.5+1:
        smallElement += 1
    for j in range(N):
        if A[i] % A[j] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1
Max = max(A)


for x in range(2,int(1000000000**0.5)+1):
    count = 0

    #配列Aの中から1つの要素だけを除いた配列Aにおける最大の最大公約数をsekiを走査
    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x
print(seki)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    g_l = [[0, 0] for _ in range(n + 1)]

    for i in range(n):
        g_l[i+1][0] = fractions.gcd(g_l[i][0], a[i])
        g_l[-i-2][1] = fractions.gcd(g_l[-i-1][1], a[-i-1])
    m_g = 0
    for i in range(n-1):
        m_g = max(m_g, fractions.gcd(g_l[i][0], g_l[i + 1][1]))
    print(m_g)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
# ABC125 C - GCD on Blackboard
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

l = n*[0]
r = n*[0]
ans = 0

for i in range(n-1):
    l[i+1] = gcd(l[i],a[i])

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

for i in range(n-1):
    ans = max(ans,gcd(l[i],r[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC125 C - GCD on Blackboard
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

l = n*[0]
r = n*[0]
m = n*[0]

for i in range(n-1):
    l[i+1] = gcd(l[i],a[i])

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

for i in range(n-1):
    m[i] = gcd(l[i],r[i])
print(max(m))

Submission status: Wrong Answer

Solution code:
#C
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)>2:
    g=gcd(a[0],a[1])
    for i in range(2,n):
        g=gcd(g,a[i])
    for i in range(n):
        a[i]//=g
    G=gcd(a[0],a[1])
    if G!=1:
        for i in range(2,n):
            if gcd(G,a[i])==1:
                a[i]=G
                break
            G=gcd(G,a[i])
        l=gcd(a[0],a[1])
        for i in range(2,n):
            l=gcd(l,a[i])
        print(g*l)
    else:
        l=gcd(a[0],a[2])
        for i in range(3,n):
            l=gcd(l,a[i])
        m=gcd(a[1],a[2])
        for i in range(3,n):
            m=gcd(m,a[i])
        print(max(g*l,g*m))
else:
    print(max(a[0],a[1]))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
array = list(map(int,input().split()))
gcd_arr = [array[0]]

for i in range(N-1):
  gcd_arr.append(gcd(gcd_arr[-1],array[i+1]))

gcd_arr.reverse()

for i in range(N-1):
  if gcd_arr[i+1] > gcd_arr[i]:
    break
    

new_gcd1 = array[1]
for j in range(N-2):
  new_gcd1 = gcd(new_gcd1,array[j+2])
  
num = array.pop(N-i-1)
new_gcd2 = array[0]
for i in range(N-2):
  new_gcd2 = gcd(new_gcd2,array[i+1])
  
print(max(new_gcd1,new_gcd2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    M = [0] * N
    L = [0] * (N+2)
    R = [0] * (N+2)
    for i in range(1,N+1):
        i_r = N-i
        L[i] = gcd(L[i-1], A[i-1])
        R[i_r] = gcd(R[i_r+1], A[i_r])
        
    for i in range(N):
        M[i] = gcd(L[i], R[i+1])

    print(max(M))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
array = list(map(int,input().split()))
gcd_arr = [array[0]]

for i in range(N-1):
  gcd_arr.append(gcd(gcd_arr[-1],array[i+1]))

gcd_arr.reverse()

for i in range(N-1):
  if gcd_arr[i+1] > gcd_arr[i]:
    break
    

new_gcd1 = array[1]
for i in range(N-2):
  new_gcd1 = gcd(new_gcd1,array[i+2])
array.pop(N-i-1)
new_gcd2 = array[0]
for i in range(N-2):
  new_gcd2 = gcd(new_gcd2,array[i+1])
print(max(new_gcd1,new_gcd2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
array = list(map(int,input().split()))
gcd_arr = [array[0]]

for i in range(N-1):
  gcd_arr.append(gcd(gcd_arr[-1],array[i+1]))

print(gcd_arr)
gcd_arr.reverse()

for i in range(N-1):
  if gcd_arr[i+1] > gcd_arr[i]:
    break
    

new_gcd1 = array[1]
for i in range(N-2):
  new_gcd1 = gcd(new_gcd1,array[i+2])
array.pop(N-i-1)
new_gcd2 = array[0]
for i in range(N-2):
  new_gcd2 = gcd(new_gcd2,array[i+1])
print(max(new_gcd1,new_gcd2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
array = list(map(int,input().split()))
gcd_arr = [array[0]]

for i in range(N-1):
  gcd_arr.append(gcd(gcd_arr[-1],array[i+1]))
  
gcd_arr.reverse()

for i in range(N-1):
  if gcd_arr[i+1] > gcd_arr[i]:
    break
    
if (N-i-1) == 1:
  new_gcd1 = array[1]
  for i in range(N-2):
    new_gcd1 = gcd(new_gcd1,array[i+2])
  array.pop(1)
  new_gcd2 = array[0]
  for i in range(N-2):
    new_gcd2 = gcd(new_gcd2,array[i+1])
  print(max(new_gcd1,new_gcd2))
  
else:
  array.pop(N-i-1)  
  new_gcd = array[0]
  for i in range(N-2):
    new_gcd = gcd(new_gcd,array[i+1])

  print(new_gcd)

Submission status: Wrong Answer

Solution code:
#C
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)>2:
    b=[]
    c=float("inf")
    for i in range(1,n):
        d=gcd(a[0],a[i])
        b.append(d)
    b.sort()
    e=[]
    for i in range(2,n):
        e.append(gcd(a[1],a[i]))
    e.sort()
    print(max(b[1],e[0]))
else:
    print(max(a[0],a[1]))

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
max_val = 0
for i in range(N-1):
    for j in range(N-1):
        if i == j+1:
            continue
        if max_val < fractions.gcd(A[i], A[j+1]):
            max_val = fractions.gcd(A[i], A[j+1])

print(max_val)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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




class SegmentTree:
    def __init__(self, init_val, ide_ele, op):
        n = len(init_val)
        self.num = 2 ** (n - 1).bit_length()
        self.seg = [ide_ele] * 2 * self.num
        self.ide_ele = ide_ele
        self.op = op
        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]
            # built
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.op(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 + 1:
            k = (k - 1) // 2
            self.seg[k] = self.op(self.seg[k * 2 + 1], self.seg[k * 2 + 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:
                res = self.op(res, self.seg[p])
            if q & 1 == 1:
                res = self.op(res, self.seg[q])
            p = p // 2
            q = (q - 2) // 2
        if p == q:
            res = self.seg[p]
        else:
            res = self.op(self.seg[p], self.op(res, self.seg[q]))
        return res



n = I()
L = LI()
ST = SegmentTree(L, 0, gcd)
print(max([gcd(ST.query(0, i), ST.query(i + 1, n)) for i in range(n)]))