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=list(map(int,input().split()))

ra=list(reversed(a))

left=[]
right=[]
import math
k=math.gcd(a[0],a[1])
left.append(a[0])
left.append(k)
for i in range(2,n-1):
  k=math.gcd(k,a[i])
  left.append(k)

k=math.gcd(ra[0],ra[1])
right.append(ra[0])
right.append(k)
for i in range(2,n-1):
  k=math.gcd(k,ra[i])
  right.append(k)

#print(left)
#print(right)
ans=[right[-1]]
for i in range(1,n-1):
  ans.append(math.gcd(left[i-1],right[len(left)-i-1]))
  ans.append(left[-1])
print(max(ans))

Submission status: Wrong Answer

Solution code:
import math

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

# x=math.gcd(a[0],a[1])
# for i in range(1,n):
#     x=math.gcd(x,a[i])

max=0
a.sort()

for i in range(n):
    # if i==n-1:
    #     s=a[i-1]
    # else:
    #     s=a[i+1]
    s=a[0]

    for j in range(n):
            if j!=i:
                s=math.gcd(s,a[j])
    else:
        if max<s:
            max=s

print(max)

Submission status: Wrong Answer

Solution code:
import math

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

# x=math.gcd(a[0],a[1])
# for i in range(1,n):
#     x=math.gcd(x,a[i])

max=0
for i in range(n):
    if i==n-1:
        s=a[i-1]
    else:
        s=a[i+1]
        for j in range(n):
            if j!=i:
                s=math.gcd(s,a[j])
        else:
            if max<s:
                max=s

print(max)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = input()
a = list(map(int, input().split()))
b = sorted(set(a))
if len(b) == 1:
  print(b[0])
  sys.exit()
pl = []
ql = []
for i in b[1:]:
  pl.append(math.gcd(b[0], i))
for i in b[2:]:
  ql.append(math.gcd(b[1], i))
pls = sorted(pl)
qls = sorted(ql)
if len(qls) == 0 or a.count(b[0]) > 1:
  print(pls[min(1, len(pls) - 1)])
else:
  print(max(pls[min(1, len(pls) - 1)], qls[0]))

Submission status: Wrong Answer

Solution code:
import math
import sys

n = input()
a = list(map(int, input().split()))
b = sorted(set(a))
if len(b) == 1:
  print(b[0])
  sys.exit()
pl = []
ql = []
for i in b[1:]:
  pl.append(math.gcd(b[0], i))
for i in b[2:]:
  ql.append(math.gcd(b[1], i))
pls = sorted(pl)
qls = sorted(ql)
if len(qls) == 0:
  print(pls[min(1, len(pls) - 1)])
else:
  print(max(pls[min(1, len(pls) - 1)], qls[0]))

Submission status: Wrong Answer

Solution code:
import math
import sys

n = input()
a = list(map(int, input().split()))
b = sorted(set(a))
if len(b) == 1:
  print(b[0])
  sys.exit()
pl = []
ql = []
for i in b[1:]:
  pl.append(math.gcd(b[0], i))
for i in b[2:]:
  ql.append(math.gcd(b[1], i))
pls = sorted(pl)
qls = sorted(ql)
if len(qls) == 0:
  print(pls[min(1, len(pls) - 1)])
else:
  print(max(pls[min(1, len(pls) - 1)], qls[min(1, len(qls) - 1)]))

Submission status: Wrong Answer

Solution code:
import math

N = int(input().rstrip())
A = list(map(int,input().rstrip().split()))
l = [A[0]]
r = [A[-1]]
for i in range(len(A)-1):
    l.append(math.gcd(A[i+1],l[i]))
    r.append(math.gcd(A[-(i+2)],r[i]))
ans = []
ans.append(r[-2])
for i in range(len(A)-2):
    ans.append(math.gcd(l[i],r[-i]))
ans.append(l[-2])
print(max(*ans))

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
A=list(map(int,input().split()))
a=math.gcd(A[0],A[1])
b=A[0]
c=A[1]
for i in range(2,N):
  a=math.gcd(a,A[i])
  b=max(a,math.gcd(b,A[i]))
  c=max(a,math.gcd(c,A[i]))
print(max(a,b,c))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a_lis = list(map(int, input().split()))
a_lis.sort()
#print(a_lis)
ans = a_lis[0]
ans_list = []
 
for i in a_lis:
    an = math.gcd(ans, i) 
    ans_list.append(an)
    ans = an
#print(a_lis)   
#print(ans_list)
ts = ans_list.index(ans_list[-1])
#print(ts)
if ts ==1 and n is not 2:
    if math.gcd(a_lis[0], a_lis[1]) == math.gcd(a_lis[1],a_lis[2]):
        a_lis.pop(1)
    else:
        a_lis.pop(0)
elif n is 2:
    a_lis.pop(0)
else:
    a_lis.pop(ts)
#print(a_lis)
ans_0 = a_lis[0]
for i in a_lis:
    ans_0 = math.gcd(i,ans_0)
print(ans_0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
L = [0] * (n+2)
L[0] = a[0]
R = [0] * (n+2)
R[-1] = a[-1]
for i in range(n):
    L[i+1] = math.gcd(a[i], L[i])
    R[-(i+2)] = math.gcd(a[-(i+1)], R[-(i+1)])

ans = 0
for i in range(1, n):
    if i - 1 == 0:
        ans = max(ans, R[i+1])
    elif i == n:
        ans = max(ans, L[i-1])
    else:
        ans = max(ans, math.gcd(L[i-1], R[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
L = [0] * (n+2)
L[0] = a[0]
R = [0] * (n+2)
R[-1] = a[-1]
for i in range(n):
    L[i+1] = math.gcd(a[i], L[i])
    R[-(i+2)] = math.gcd(a[-(i+1)], R[-(i+1)])

ans = max(R[1], L[-2])
for i in range(1, n):
    if i - 1 == 0:
        ans = max(ans, R[i+1])
    elif i == n:
        ans = max(ans, L[i-1])
    else:
        ans = max(ans, math.gcd(L[i-1], R[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
l = 1
for i in range(n):
    l *= a[i]
L = [0] * (n+2)
L[0] = l
R = [0] * (n+2)
R[-1] = l

for i in range(n):
    L[i+1] = math.gcd(a[i], L[i])
    R[-(i+2)] = math.gcd(a[-(i+1)], R[-(i+1)])

ans = R[0]
for i in range(1, n):
    ans = max(ans, math.gcd(L[i-1], R[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
#全体のgcdをとる際に最小にしてくるものを、他の全てのgcdに入れ替えてやる
import math
n = int(input())
a_lis = list(map(int, input().split()))
a_lis.sort()
ans = a_lis[0]
ans_list = []

for i in a_lis[1:]:
    an = math.gcd(ans, i) 
    ans_list.append(an)
    ans = an
    
#print(ans_list)
ts = ans_list.index(ans_list[-1]) +1
a_lis.pop(ts)
ans_0 = a_lis[0]
for i in a_lis[1:]:
  ans_0 = math.gcd(i,ans_0)
print(ans_0)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
arr = list(map(int, input().split()))
gcd_right = [arr[0]]
for i in range(1,N-1):
    gcd_right.append(math.gcd(gcd_right[i-1],arr[i]))
arr = arr[::-1]
gcd_left = [arr[0]]
for i in range(1,N-1):
    gcd_left.append(math.gcd(gcd_left[i-1],arr[i]))
gcd_left = gcd_left[::-1]
ans = max(gcd_right[-1],gcd_left[0])
for i in range(N-2):
    ans = max(ans,math.gcd(gcd_left[N-2-i],gcd_right[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=[0]+A
import math

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

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

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def is_prime(n):
    if n==0 or n==1: return False
    for i in range(2, int(n**0.5)+1):
        if n%i==0:
            return False
    return True

def resolve():
    N = I()
    A = LI()

    # まずgdcを求める
    gcd = A[0]
    for i in range(1, N):
        gcd = math.gcd(A[i], gcd)

    # Aの中でgcdで割って素数だったやつを1個だけ除外して再度gcdを求める
    idx = -1
    for i in range(N):
        B = A[i] // gcd
        if is_prime(B):
            idx = i
            break

    if idx == 0:
        ans = A[1]
    else:
        ans = A[0]
    for i in range(1, N):
        if i != idx:
            ans = math.gcd(A[i], ans)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromleft = list(accumulate(a, math.gcd))
a.reverse()
fromright = list(accumulate(a, math.gcd))
fromright.reverse()
a.reverse()

gcd = []

gcd.append(fromright[1])
for i in range(1, n-1):
    gcd.append(math.gcd(fromleft[i-1], fromright[i+1]))
    print(i, fromright[i-1], fromleft[i+1])

gcd.append(fromleft[n-2])

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

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
    gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[1])

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

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[1])

if n == 2:
  print(math.gcd(a[1], a[0]))
else:
  print(max(gcd))

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[1])

if n == 2:
  print(max(a))

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[1])

if n == 2:
  print(max(a))
else:
  print(max(gcd))

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[1])

print(gcd)

if n == 2:
  print(max(a))
else:
  print(max(gcd))

Submission status: Wrong Answer

Solution code:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

if n == 2:
  print(math.gcd(a[1], a[0]))
else:
  print(max(gcd))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

g = []

for i in range(n):
  r = a[i]
  a.remove(r)
  g.append(reduce(math.gcd, a))
  a.append(r)

print(max(g))

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().strip().split()))
x = a[1]

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

res = x
x = a[0]

for i in range(1, n-1):
    y = x
    for j in range(i+1, n):
        y = gcd(y, a[j])
    if res < y:
        res = y
    x = gcd(x, a[i])

y = gcd(x, a[n-1])
if res < y:
    res = y
print(res)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

ans = 0
for i in range(N):
    num_list = nums[:i] + nums[i+1:]
    for j in range(N-1):
        gcd = num_list[0]        
        gcd = math.gcd(gcd,num_list[j])
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Wrong Answer

Solution code:
# 最大公約数
def gcd(a, b):
    if a == 0 or b == 0:
        ret = max(a,b)
    else:
        if a<b:
            a,b = b,a
        r = a%b
        while r != 0:
            a = b
            b = r
            r = a % b
    return b

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[-2-i] = gcd(R[-1-i], a[-1-i])
    
ans = 0
for i in range(n):
    G = gcd(L[i], R[i+1])
    ans = max(ans, G)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(n)]
r=[0 for i in range(n)]
l[0]=a[0]
r[0]=a[-1]
for i in range(n-1):
    l[i+1]=gcd(l[i],a[i+1])
for i in range(n-1):
    r[i+1]=gcd(r[i],a[-2-i])
ans=[0 for i in range(n)]
for i in range(1,n-1):
    ans[i]=gcd(l[i-1],r[-i+n-2])
ans[0]=r[n-1]
ans[n-1]=l[n-1]
print(max(ans))

Submission status: Wrong Answer

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

for i in range(n):
    a[i]=a[i]//g
x=0
y=n-1
j=(x+y)//2
while y-x>1:
    j=(x+y)//2
    G=gcd(a[x],a[x+1])
    for i in range(x,j+1):
        G=gcd(G,a[i])
    if G==1:
        y=j
    else:
        x=j
s=[a[i] for i in range(n) if i!=x]
l=[a[i] for i in range(n) if i!=y]
p=gcd(s[0],s[-1])
q=gcd(l[0],l[-1])
for i in range(n-1):
    p=gcd(p,s[i])
for i in range(n-1):
    q=gcd(q,l[i])
print(g*max(p,q))

Submission status: Wrong Answer

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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

#a0div = make_divisors(a[0])
adi = sorted(set(make_divisors(a[0]) + make_divisors(a[1])))
adiv = adi + [max(adi)+1]

def is_ok(arg):
    #print(f"index{arg}でーす{adiv[arg]}")
    cnt = 0
    for i in range(n):
        if a[i]%adiv[arg] != 0:
            cnt += 1
            #print(str(a[i])+"×")

        if cnt>=2:
            #print("だめ"+str(a[i])+" iは"+str(i))
            return False
            break    
    else:
        #print("ok-")
        return True


def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

#print(adiv)
#print(meguru_bisect(len(adiv),0))
print(adiv[meguru_bisect(len(adiv),0)])

Submission status: Wrong Answer

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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

#a0div = make_divisors(a[0])
adi = sorted(set(make_divisors(a[0]) + make_divisors(a[1])))
adiv = adi + [max(adi)+1]

def is_ok(arg):
    #print(f"index{arg}でーす{adiv[arg]}")
    cnt = 0
    for i in range(n):
        if a[i]%adiv[arg] != 0:
            cnt += 1
            #print(str(a[i])+"×")
        if cnt>=2:
            #print("だめ"+str(a[i])+" iは"+str(i))
            return False
            break    
    else:
        #print("ok-")
        return True


def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

#print(adiv)
#print(meguru_bisect(len(adiv),1))
print(adiv[meguru_bisect(len(adiv),1)])

Submission status: Wrong Answer

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    """
    N = read_int()
    A = read_ints()
    prefix = [-1]*N
    # prefix[i] is gcd of numbers 0..i-2
    suffix = [-1]*N
    for i in range(N-1):
        if i == 0:
            prefix[i+1] = A[i]
        else:
            prefix[i+1] = math.gcd(prefix[i], A[i])
    for i in range(N-1, 0, -1):
        if i == N-1:
            suffix[i-1] = A[i]
        else:
            suffix[i-1] = math.gcd(suffix[i], A[i])
    max_gcd = -1
    for i in range(N):
        gcd = None
        if prefix[i] != -1:
            gcd = prefix[i]
        if gcd is None:
            gcd = suffix[i]
        else:
            gcd = math.gcd(prefix[i], suffix[i])
        max_gcd = max(max_gcd, gcd)
    return max_gcd


if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
def main():
    import math
    n = int(input())
    a = sorted(list(map(int,input().split())))
    if n==2:
        print(a[1])
        return
    g1 = math.gcd(a[0],a[1])
    g2 = math.gcd(a[1],a[2])
    g3 = math.gcd(a[0],a[2])
    g4 = max(g1,g2,g3)
    ans = [1]
    for i in range(2,int(g4**0.5)):
        if g4%i==0:
            ans.append(i)
    if g4!=1:
        ans.append(g4)
    d = len(ans)
    for i in range(d):
        c = 0
        b = ans[d-i-1]
        for j in range(n):
            if a[j]%b==0:
                c += 1
        if c==d or c+1==d:
            print(b)
            return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd

n = int(input())
a = list(map(int, input().split()))[::-1]
l = [a[0], a[-1]]
r = [a[0]]
for x in a[1:-1]:
    l.append(gcd(l[-1], x))
    r.append(gcd(r[-1], x))
r = r[::-1]
r.append(a[-1])
print(max(gcd(l[i], r[i]) for i in range(n)))

Submission status: Wrong Answer

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

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

left_ = [0] * (n + 1)
right_ = [0] * (n + 1)
ans = []

for i in range(n):
    left_[i] = gcd( left_[i-1], data[i] )

for i in range(n-1, 0, -1):
    right_[i] = gcd( right_[i+1], data[i] )

print( left_ )
print( right_ )

for i in range(n):
    ans += [ gcd( left_[i-1], right_[i+1] ) ]

print( max(ans) )

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = sorted(list(map(int,input().split())))
ans = []

for n in range(N):
  B = A[:n]+A[n+1:]
  ans+=[np.gcd.reduce(B)]

print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

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

if N==2:
  print(A[1])
  exit()

res=[]
common=[]
for i in range(2,int(A[1]**.5+5)):
  count = 0
  idx=-1
  for j in range(len(A)):
    if A[j] % i != 0:
      count += 1
      idx=j
    if count == 2:break
  if count == 1:
    res.append((i,idx))
  if count == 0:
    common.append(i)

common2 = 1
for i in range(len(common)):
  common2 = common2*common[i]//gcd(common2,common[i])

counter = defaultdict(lambda:common2)

for i in range(len(res)):
  a,b=counter[res[i][1]],res[i][0]
  counter[res[i][1]] = a*b//gcd(a,b)

if len(counter.values()):
  print(sorted(counter.values(),reverse=True)[0])
else:
  print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = tuple(map(int, input().split()))

facs = dict()
for a in A:
    # 約数列挙
    facs.setdefault(a, 1)
    for i in range(2, int(a**0.5)+1):
        if a%i == 0:
            facs.setdefault(i, 0)
            facs[i] += 1
            if i*i != a:
                tmp = a//i
                facs.setdefault(tmp, 0)
                facs[tmp] += 1
ans = 0    
for k, v in facs.items():
    if v >= n-1:
        ans = max(ans, k)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

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

if N==2:
  print(A[1])
  exit()

res=[]
for i in range(2,int(A[1]**.5+5)):
  count = 0
  idx=-1
  for j in range(len(A)):
    if A[j] % i != 0:
      count += 1
      idx=j
    if count == 2:break
  if count == 1:
    res.append((i,idx))

counter = defaultdict(lambda:1)

for i in range(len(res)):
  a,b=counter[res[i][1]],res[i][0]
  counter[res[i][1]] = a*b//gcd(a,b)

if len(counter.values()):
  print(sorted(counter.values(),reverse=True)[0])
else:
  print(1)

Submission status: Wrong Answer

Solution code:
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()

# print(R)
# print(L)
m = []
m.append(R[1])
m.append(L[n-1])
# print(m)

if n>2:
    for xi in range(1,n-1):
        m.append(math.gcd(L[xi-1],R[xi+1]))
        # print(xi, L[xi-1],R[xi+1])

# print(m)
print(max(m))

Submission status: Wrong Answer

Solution code:
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()

print(R)
print(L)
m = []
m.append(R[1])
m.append(L[n-1])
# print(m)

if n>2:
    for xi in range(1,n-1):
        m.append(math.gcd(L[xi-1],R[xi+1]))
        print(xi, L[xi-1],R[xi+1])

print(m)
print(max(m))

Submission status: Wrong Answer

Solution code:
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()

# print(R)
# print(L)
m = []
m.append(R[1])
m.append(L[n-1])
# print(m)

for xi in range(1,n-1):
    m.append(math.gcd(L[xi-1],R[xi+1]))
    # print(xi, L[xi-1],R[xi+1])

# print(m)
print(max(m))

Submission status: Wrong Answer

Solution code:
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    L.append(math.gcd(gcdl,a[xi]))

for xi in range(n-2,-1,-1):
    R.append(math.gcd(gcdr,a[xi]))

R.reverse()

m = []
m.append(R[1])
m.append(L[n-1])
# print(m)

for xi in range(1,n-1):
    m.append(math.gcd(L[xi-1],R[xi+1]))
    # print(xi, L[xi-1],R[n-xi-2])

# print(L)
# print(R)
# print(m)
print(max(m))

Submission status: Wrong Answer

Solution code:
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    L.append(math.gcd(gcdl,a[xi]))

for xi in range(n-2,-1,-1):
    R.append(math.gcd(gcdr,a[xi]))

m = []
m.append(R[n-2])
m.append(L[n-2])
# print(m)

for xi in range(1,n-1):
    m.append(math.gcd(L[xi-1],R[n-xi-2]))
    # print(xi, L[xi-1],R[n-xi-2])

# print(L)
# print(R)
# print(m)
print(max(m))

Submission status: Wrong Answer

Solution code:
# abc125_c.py
# https://atcoder.jp/contests/abc125/tasks/abc125_c

# C - GCD on Blackboard /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# N個の整数 A1,A2,...,ANが黒板に書かれています。
# あなたはこの中から整数を 1つ選んで、1 以上 109以下の好きな整数に書き換えます。
# 元の整数と同じ整数に書き換えても構いません。
# 書き換えた後の N個の整数の最大公約数の最大値を求めてください。

# 制約
#     入力は全て整数である。
#     2≤N≤105
#     1≤Ai≤109

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# A1 A2 ... AN

# 出力
# 書き換えた後の N個の整数の最大公約数の最大値を出力せよ。

# 入力例 1
# 3
# 7 6 8

# 出力例 1
# 2

# 7を 4 に書き換えると 3 つの整数の最大公約数は 2となり、これが最大です。

# 入力例 2
# 3
# 12 15 18

# 出力例 2
# 6

# 入力例 3
# 2
# 1000000000 1000000000

# 出力例 3
# 1000000000

# 元の整数と同じ整数に書き換えることも可能です。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # line = lines[0]
    N = int(lines[0])
    # A, B, T = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(Q):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = None

    for i in range(N):
        tmps = list()
        for j in range(N):
            if i != j:
                tmps.append(values[j])
        ma = get_max(tmps)
        if result is None:
            result = ma
        elif result < ma:
            result = ma

    return [result]


def get_max(values):
    tmps = set(values)
    while True:
        mi = min(tmps)
        tmps =  [tmp % mi for tmp in tmps if tmp > 0]
        tmps = [tmp for tmp in tmps if tmp > 0]
        if tmps == []:
            return mi


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '7 6 8']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['3', '12 15 18']
        lines_export = [6]
    if pattern == 3:
        lines_input = ['2', '1000000000 1000000000']
        lines_export = [1000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
left = [0] * N
x = A[0]
for i in range(N):
    x = gcd(x,A[i])
    left[i] = x

right = [0] * N
x = A[-1]
for i in range(N):
    x = gcd(x,A[N-i-1])
    right[i] = x
v = [0] * N
v[0] = right[-2]
v[-1] = left[-2]
for i in range(1,N-1):
    v[i] = gcd(left[i-1], right[i-1])

print(max(v))

Submission status: Wrong Answer

Solution code:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
left = [0] * N
x = A[0]
for i in range(N):
    x = gcd(x,A[i])
    left[i] = x

right = [0] * N
x = A[-1]
for i in range(N):
    x = gcd(x,A[N-i-1])
    right[i] = x
v = [0] * N
v[0] = right[-2]
v[-1] = left[-2]
for i in range(1,N-1):
    print(left[i-1],right[i-1])
    v[i] = gcd(left[i-1], right[i-1])

print(max(v))

Submission status: Wrong Answer

Solution code:
n = input()
x = input().split()
for i in range(0 , int(n)):
	x[i] = int(x[i])
min = min(x)

for i in range(min, 1 , -1):
	tmp = 0
	for ii in x:
		if int(ii) % i == 0:
			tmp += 1
	if tmp >= int(n) - 1:
		print(i)
		break

Submission status: Wrong Answer

Solution code:
n = input()
x = input().split()
for i in range(0 , int(n)):
	x[i] = int(x[i])
min = min(x)

for i in range(min, 1 , -1):
	tmp = 0
	for ii in x:
		if ii % i == 0:
			tmp += 1
	if tmp >= int(n) - 1:
		print(i)
		break

Submission status: Wrong Answer

Solution code:
# わからん 約数の数が多いほうが強そうなイメージ
# python3でWAとTLEなったのでどうせWAなることは自明だがpypyで試してみる


def divlis(n):
    ret = {1: 1}
    m = n
    for i in range(2, int(m**0.5) + 1):
        if n % i == 0:
            ret[i] = 1
            n //= i
            while n % i == 0:
                ret[i] += 1
                n //= i
    if n > 1:
        ret[n] = 1
    return ret


n = int(input())
a = list(map(lambda x: divlis(int(x)), input().split()))
a = sorted(a, key=lambda av: sum(av.values()), reverse=True)

ansset = a[0]
for i in range(1, n - 1):
    for av in ansset:
        if av in a[i].keys():
            ansset[av] = min(ansset[av], a[i][av])

ans = 1
for k, v in ansset.items():
    ans *= k**v
print(ans)

Submission status: Wrong Answer

Solution code:
# わからん 約数の数が多いほうが強そうなイメージ


def divlis(n):
    ret = {1: 1}
    m = n
    for i in range(2, int(m**0.5) + 1):
        if n % i == 0:
            ret[i] = 1
            n //= i
            while n % i == 0:
                ret[i] += 1
                n //= i
    if n > 1:
        ret[n] = 1
    return ret


n = int(input())
a = list(map(lambda x: divlis(int(x)), input().split()))
a = sorted(a, key=lambda av: sum(av.values()), reverse=True)

ansset = a[0]
for i in range(1, n - 1):
    for av in ansset:
        if av in a[i].keys():
            ansset[av] = min(ansset[av], a[i][av])

ans = 1
for k, v in ansset.items():
    ans *= k**v
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[*map(int,input().split())]
def divisor(x):
  s={1,x}
  for i in range(2,int(x**0.5)+1):
    if x%i<1: s|={i,x//i}
  return sorted(s)
c={}
for i in l:
  for j in divisor(i):
    c[j]=c.get(j,0)+1
t=1
for i in c:
  if c[i]>=n-1:
    t=i
print(t)