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())
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=0
for i in c:
  if c[i]>=n-1:
    t=i
print(t)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(n) for n in input().split()]

import math, copy

def all_gcd(l):
    a = l[0]
    for i in range(1,len(l)):
        b = l[i]
        a = math.gcd(a, b)
    return a

max_gcd = 0

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

    max_gcd = max(max_gcd, math.gcd(L, R)) 

print(max_gcd)

Submission status: Wrong Answer

Solution code:
#<125>
import itertools
import math
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in itertools.combinations(A, 2):
    ans += [math.gcd(i[0], i[1])]
    
    #print(math.gcd(i[0], i[1]))
print(max(ans))

Submission status: Wrong Answer

Solution code:

#<125>
import itertools
import math
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in itertools.combinations(A, 2):
    ans = max(0, math.gcd(i[0], i[1]))
    
    #print(math.gcd(i[0], i[1]))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd

def init(init_val):
    for i in range(N):
        seg[i+num-1] = init_val[i]
    for i in range(num-2, -1, -1):
        seg[i] = gcd(seg[2*i+1], seg[2*i+2])

def update(k, x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = gcd(seg[k*2+1, seg[k*2+2]])

def query(p, q):
    if q <= p:
        return ide_ele
    p += num-1
    q += num-2
    res = ide_ele
    while p-q > 1:
        if p&1 == 0:
            res = gcd(res, seg[p])
        if q&1 == 1:
            res = gcd(res, seg[q])
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res = gcd(res, seg[p])
    else:
        res = gcd(gcd(res, seg[p]), seg[q])
    return res

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

ide_ele = 0
num = 2**(N-1).bit_length()
seg = [ide_ele]*2*num

init(A)
ans = -1
for i in range(N):
    ans = max(ans, gcd(query(0, i), query(i+1, N)))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n = int(input())
l = list(map(int,input().split()))
mi = 1
gcd_l = [l[0]]
gcd_r = [l[-1]]
for i in range(1,n):
  gcd_l.append(gcd(l[i],gcd_l[-1]))
for i in range(n-2,-1,-1):
  gcd_r.append(gcd(l[i],gcd_r[-1]))
for i in range(0,n-3):
  t = gcd(gcd_l[i], gcd_r[i+2])
  mi = max(mi,t)
mi = max(mi,gcd_r[-2])
mi = max(mi,gcd_l[-2])
print(mi)

Submission status: Wrong Answer

Solution code:
from math import gcd
n = int(input())
l = list(map(int,input().split()))
mi = 1
gcd_l = [l[0]]
gcd_r = [l[-1]]
for i in range(1,n):
  gcd_l.append(gcd(l[i],gcd_l[-1]))
for i in range(n-2,-1,-1):
  gcd_r.append(gcd(l[i],gcd_r[-1]))
for i in range(0,n-1):
  t = gcd(gcd_l[i], gcd_r[i])
  mi = max(mi,t)
#print(gcd_r)
#print(gcd_l)
mi = max(mi,gcd_r[1])
mi = max(mi,gcd_l[-2])
print(mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
from functools import reduce
ans=0
def gcd(numbers):
  return reduce(math.gcd, numbers)
import itertools
l=list(map(int, input().split()))
l=list(set(l))
if len(l)==1:
  print(l[0])
  exit()
elif len(l)==2:
  print(max(l))
  exit()
else: 
  for v in itertools.combinations(l, len(l)-1):
    ans=max(ans, gcd(v))
print(ans)

Submission status: Wrong Answer

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

N=int(input())
array=sorted([int(x) for x in input().split()])
prefix_GCD=[0]*(N)
suffix_GCD=[0]*(N)
currentGCD=array[0]

for i in range(N):
	prefix_GCD[i]=gcd(currentGCD,array[i])
	currentGCD=gcd(currentGCD,(array[i]))
currentGCD=array[N-1]

for i in range(N-1,-1,-1):
	suffix_GCD[i]=gcd(currentGCD,(array[i]))
	currentGCD=gcd(currentGCD,(array[i]))
	
highest=0
for i in range(N):
	if i==0:
		gcdwithout=suffix_GCD[1]
	elif i==N-1:
		gcdwithout=prefix_GCD[-2]
	else:
		gcdwithout=gcd(prefix_GCD[i-1],suffix_GCD[N-i]	)
	highest=max(highest,gcdwithout)
print(highest)

Submission status: Wrong Answer

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

N=int(input())
array=sorted([int(x) for x in input().split()])
prefix_GCD=[0]*(N)
suffix_GCD=[0]*(N)
currentGCD=array[0]
for i in range(N):
	prefix_GCD[i]=gcd(currentGCD,array[i])
	currentGCD=gcd(currentGCD,(array[i]))
currentGCD=array[N-1]
j=0
for i in range(N-1,-1,-1):
	suffix_GCD[i]=gcd(currentGCD,(array[i]))
	currentGCD=gcd(currentGCD,(array[i]))
highest=0
for i in range(N):
	if i==0:
		gcdwithout=suffix_GCD[1]
	elif i==N-1:
		gcdwithout=prefix_GCD[-2]
	else:
		gcdwithout=gcd(prefix_GCD[i-1],suffix_GCD[-i])
	highest=max(highest,gcdwithout)
print(highest)

Submission status: Wrong Answer

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

N=int(input())
array=sorted([int(x) for x in input().split()])
prefix_GCD=[0]*(N)
suffix_GCD=[0]*(N)
currentGCD=array[0]
for i in range(N):
	prefix_GCD[i]=gcd(currentGCD,array[i])
	currentGCD=gcd(currentGCD,(array[i]))
currentGCD=array[N-1]
j=0
for i in range(N-1,-1,-1):
	suffix_GCD[i]=gcd(currentGCD,(array[i]))
	currentGCD=gcd(currentGCD,(array[i]))
highest=0
for i in range(N):
	gcdwithout=gcd(prefix_GCD[i-1],suffix_GCD[-i])
	highest=max(highest,gcdwithout)
print(highest)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

N = INT()
A = LIST()

def max_gcd(n):
	g = []
	for p, q in factorization(n):
		g += [p]*q
	g.sort(reverse = True)
	cnt = [0]*len(g)

	for a in A:
		for i in range(len(g)):
			if a%g[i] == 0:
				cnt[i] += 1
				a //= g[i]

	ans = 1
	flg = True
	for i in range(len(g)):
		if cnt[i] == N:
			ans *= g[i]
		elif cnt[i] == N-1 and flg:
			ans *= g[i]
			flg = False
	return ans

print(max(max_gcd(A[0]), max_gcd(A[1])))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

N = INT()
A = LIST()

def max_gcd(n):
	g = []
	for p, q in factorization(n):
		g += [p]*q
	g.sort(reverse = True)
	cnt = [0]*len(g)

	for a in A:
		for i in range(len(g)):
			if a%g[i] == 0:
				cnt[i] += 1

	ans = 1
	flg = True
	for i in range(len(g)):
		if cnt[i] == N:
			ans *= g[i]
		elif cnt[i] == N-1 and flg:
			ans *= g[i]
			flg = False
	return ans

print(max(max_gcd(A[0]), max_gcd(A[1])))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

N = INT()
A = LIST()

def max_gcd(n):
	g = []
	for p, q in factorization(n):
		g += [p]*q
	cnt = [0]*len(g)

	for a in A:
		for i in range(len(g)):
			if a%g[i] == 0:
				cnt[i] += 1

	ans = 1
	flg = True
	for i in range(len(g)-1, -1, -1):
		if cnt[i] == N:
			ans *= g[i]
		elif cnt[i] == N-1 and flg:
			ans *= g[i]
			flg = False
	return ans

print(max(max_gcd(A[0]), max_gcd(A[1])))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

N = INT()
A = LIST()

def max_gcd(n):
	g = sorted([x for x, y in factorization(n)])
	cnt = [0]*len(g)

	for a in A:
		for i in range(len(g)):
			if a%g[i] == 0:
				cnt[i] += 1

	ans = 1
	flg = True
	for i in range(len(g)-1, -1, -1):
		if cnt[i] == N:
			ans *= g[i]
		elif cnt[i] == N-1 and flg:
			ans *= g[i]
			flg = False
	return ans

print(max(max_gcd(A[0]), max_gcd(A[1])))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

tmp = A[0]
idx = 0
for i in range(N):
	if tmp != gcd(tmp, A[i]):
		idx = i
		tmp = gcd(tmp, A[i])

def max_gcd(i):
	a = A.copy()
	del a[i]
	ans = a[0]
	for x in a:
		ans = gcd(ans, x)
	return ans

if idx == 1:
	print(max(max_gcd(idx-1), max_gcd(idx)))
else:
	print(max_gcd(idx))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

tmp = A[0]
idx = 0
for i in range(N):
	if tmp != gcd(tmp, A[i]):
		idx = i
		tmp = gcd(tmp, A[i])

def max_gcd(i):
	a = A.copy()
	del a[i]
	ans = a[0]
	for x in a:
		ans = gcd(ans, x)
	return ans

print(max(max_gcd(idx-1), max_gcd(idx)))

Submission status: Wrong Answer

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

B = A[1:]

if len(A) == 2:
    print(max(A))
else:
    c = []
    for b in B:
        c.append(math.gcd(b,A[0]))
    cd = sorted(c)[1]

    d = []
    for i in range(1,len(A)):
        d.append(math.gcd(A[i],A[1]))
    dd = min(d)
    print(max(cd,dd))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    left = 1
    right = a[0]
    ans = 1
    for _ in range(100):
        if left == right:
            break
        ans = (left + right) // 2
        not_divisible = 0
        for aa in a:
            if aa % ans:
                not_divisible += 1
                if not_divisible > 1:
                    break
        if not_divisible > 1:
            right = ans
        else:
            left = ans
    print(ans if len(set(a)) > 1 else a[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    left = 1
    right = a[0]
    ans = 1
    for _ in range(100000):
        if left == right:
            break
        ans = (left + right) // 2
        not_divisible = 0
        for aa in a:
            if aa % ans:
                not_divisible += 1
                if not_divisible > 1:
                    break
        if not_divisible > 1:
            right = ans
        else:
            left = ans
    print(ans if len(set(a)) > 1 else a[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

left_gcd = [0] + [0] * n + [-1]
right_gcd = [-1] + [0] * n + [0]

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

ans = 1
for i in range(1, n):
    ans = max(ans, gcd(left_gcd[i-1], right_gcd[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

drop_zero = a[1:]
drop_one = [a[0]] + a[2:]

ans_drop_zero = drop_zero[0]
for v in drop_zero:
    ans_drop_zero = gcd(ans_drop_zero, v)

ans_drop_one = drop_one[0]
for v in drop_one:
    ans_drop_one = gcd(ans_drop_one, v)

print(max(ans_drop_zero, ans_drop_one))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


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


def is_prime(v):
    if v in [2, 3]:
        return True
    for i in range(2, v):
        if i * i > v:
            return True
        if v % i == 0:
            return False


input = sys.stdin.buffer.readline
N = int(input())
A = np.array(sorted(list(map(int, input().split()))))
# print(f'{A=}')

if np.all(A == A[0]):
    print(A[0])
    exit()

primes = []
primes = np.array([a for a in A if is_prime(a)])
# print(f'{primes=}')

if len(primes) >= 3:
    print(1)
    exit()

if len(primes) == 2:
    prime = primes[0]
    v1 = prime
    for a in A:
        if a in primes:
            continue
        v1 = gcd(v1, a)
    prime = primes[1]
    v2 = prime
    for a in A:
        if a in primes:
            continue
        v2 = gcd(v2, a)
    print(max(v1, v2))
    exit()

# print('test')

if len(primes) == 1:
    prime = primes[0]
    v = A[0] if A[0] != prime else A[1]
    for a in A:
        if a == prime:
            continue
        v = gcd(v, a)
    print(v)
    exit()

v = A[0]
g = A[0]
for a in A[1:]:
    _g = gcd(g, a)
    if _g < g:
        g = _g
        v = a
# print(f'{v=}, {g=}')

ans = A[0] if A[0] != v else A[1]
for a in A:
    if a == v:
        continue
    ans = gcd(ans, a)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd

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

left = []
right = []

left.append(A[0])
for a in A[1:]:
    left.append(gcd(left[-1], a))

right.append(A[-1])
for a in A[-2::-1]:
    right.append(gcd(right[-1], a))

right = list(reversed(right))

ans = [left[1], right[-2]]

for i in range(1, len(left) - 1):
    ans.append(gcd(left[i - 1], right[i + 1]))

print(max(ans))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

N = int(input())
# A = sorted(map(int, input().split(' ')))
A = tuple(map(int, input().split(' ')))

base = reduce(gcd, A)

rest = 1
ans1 = A[0]
for a in A[1:]:
    b = gcd(ans1, a)
    if b == base and rest > 0:
        rest -= 1
    else:
        ans1 = b

rest = 1
ans2 = A[-1]
for a in A[:-1]:
    b = gcd(ans2, a)
    if b == base and rest > 0:
        rest -= 1
    else:
        ans2 = b

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)

rest = 1
ans1 = A[0]
for a in A[1:]:
    b = gcd(ans1, a)
    if b == base and rest > 0:
        rest -= 1
    else:
        ans1 = b

rest = 1
ans2 = A[-1]
for a in A[:-1]:
    b = gcd(ans2, a)
    if b == base and rest > 0:
        rest -= 1
    else:
        ans2 = b

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)

rest = 1
ans = A[0]
if ans == base:
    ans = A[1]
    rest -= 1
    A = A[1:]

for a in A[1:]:
    b = gcd(ans, a)
    if b == base and rest > 0:
        rest -= 1
    else:
        ans = b

print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)

rest = 1
ans = A[0]
if ans == base:
    ans = A[1]
    rest -= 1
    A = A[2:]

for a in A:
    b = gcd(ans, a)
    if b == base and rest > 0:
        rest -= 1
    else:
        ans = b

print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)

rest = 1
ans1 = A[0]
for a in A:
    b = gcd(ans1, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans1 = b

rest = 1
ans2 = A[-1]
for a in A:
    b = gcd(ans2, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans2 = b

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)

rest = 1
ans1 = A[0]
for a in A[1:]:
    b = gcd(ans1, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans1 = b

rest = 1
ans2 = A[-1]
for a in reversed(A[:-1]):
    b = gcd(ans2, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans2 = b

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)
rest = 1

ans1 = A[0]
for a in A:
    b = gcd(ans1, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans1 = b

ans2 = A[-1]
for a in reversed(A):
    b = gcd(ans2, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans2 = b

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

if len(A) == 2:
    print(max(A))
else:
    base = reduce(gcd, A)
    rest = 1

    ans1 = A[0]
    for a in A:
        b = gcd(ans1, a)
        if rest > 0 and b == base:
            rest -= 1
        else:
            ans1 = b

    ans2 = A[1]
    for a in A:
        b = gcd(ans2, a)
        if rest > 0 and b == base:
            rest -= 1
        else:
            ans2 = b

    print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

if len(A) == 2:
    print(max(A))
else:
    base = reduce(gcd, A)
    rest = 1

    ans1 = A[0]
    for a in A[1:]:
        b = gcd(ans1, a)
        if rest > 0 and b == base:
            rest -= 1
        else:
            ans1 = b

    ans2 = A[1]
    for a in A[1:]:
        b = gcd(ans2, a)
        if rest > 0 and b == base:
            rest -= 1
        else:
            ans2 = b

    print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

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

base = reduce(gcd, A)
rest = 1

ans1 = A[0]
for a in A[1:]:
    b = gcd(ans1, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans1 = b

ans2 = A[1]
for a in A[1:]:
    b = gcd(ans2, a)
    if rest > 0 and b == base:
        rest -= 1
    else:
        ans2 = b

print(max(ans1, ans2))

Submission status: Wrong Answer

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

import math
from functools import reduce

# 最大公約数（リスト引数）
def GCD_list(numbers):
    return reduce(math.gcd, numbers)


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

maxgcd = 1
for a in A:
    B = [x for x in A if x != a]
    if len(B) == 0:
        continue
    gcd = GCD_list(B)
    if gcd > maxgcd:
        maxgcd = gcd

print(maxgcd)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    l = [0] * (n + 1)
    for i1 in range(n):
        l[i1 + 1] = gcd(l[i1], a[i1])
    r = [0] * (n + 1)
    for j1 in range(n - 1, -1, -1):
        r[j1] = gcd(r[j1 + 1], a[j1])
    m = [0] * (n + 1)
    for k1 in range(n - 1):
        m[k1] = gcd(l[k1], r[k1 + 1])
    r = max(m)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
def main():
    n, *a = map(int, read().split())

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

    from math import sqrt
    from math import ceil
    maxa = max(a)
    maxa2 = ceil(sqrt(maxa))
    maxa2 = max(6, maxa2)  # maxa2が6未満だとエラーになる
    p = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)]
    p[0] = p[1] = False
    p[2] = p[3] = p[5] = True
    for is1 in range(3, maxa2, 2):
        for is2 in range(is1 ** 2, maxa2, is1):
            p[is2] = False
    prime_list = [i for i, b in enumerate(p) if b]

    r = 1
    jo = []
    for pre in prime_list:
        if a.count(1) >= 2:
            break
        while True:
            c = [ae % pre == 0 for ae in a]
            if all(c):
                r *= pre
                a = [ae // pre for ae in a]
            else:
                if c.count(0) == 1:
                    r *= pre
                    jo.append(pre)
                    a[c.index(0)] *= pre
                    a = [ae // pre for ae in a]
                else:
                    break
    jo.sort()

    lenjo = len(jo)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n,ans=int(input()),1
A=list(map(int,input().split()))
gcd_l,gcd_r=[],[]
l,r=A[0],A[n-1]

for i in range(n-1):
  l,r=gcd(l,A[i]),gcd(r,A[n-i-1])
  gcd_l.append(l)
  gcd_r.append(r)

for i in range(n-2):
  v=gcd(gcd_l[i],gcd_r[i])
  if v > ans:
    ans = v

if gcd_l[n-2] > ans:
  ans=gcd_l[n-2]
if gcd_r[n-2] > ans:
  ans=gcd_r[n-2]
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
def main():
    n, *a = map(int, read().split())

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

    from math import sqrt
    from math import ceil
    maxa = max(a)
    maxa2 = ceil(sqrt(maxa))
    maxa2 = max(6, maxa2)  # maxa2が6未満だとエラーになる
    p = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)]
    p[0] = p[1] = False
    p[2] = p[3] = p[5] = True
    for is1 in range(3, maxa2, 2):
        for is2 in range(is1 ** 2, maxa2, is1):
            p[is2] = False
    prime_list = [i for i, b in enumerate(p) if b]

    r = 1
    jo = []
    for pre in prime_list:
        if a.count(1) >= 2:
            break
        #if all([ae == 1 for ae in a]):
        #    break
        while True:
            c = [ae % pre == 0 for ae in a]
            if all(c):
                r *= pre
                a = [ae // pre for ae in a]
            else:
                if c.count(0) == 1:
                    r *= pre
                    jo.append(pre)
                    a[c.index(0)] *= pre
                    a = [ae // pre for ae in a]
                else:
                    break
    jo.sort()
    lenjo = len(jo)
    for joe in jo[:lenjo - 1]:
        r = r // joe
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())

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

    from math import sqrt
    from math import ceil
    maxa = max(a)
    maxa2 = ceil(sqrt(maxa))
    maxa2 = max(6, maxa2)  # maxa2が6未満だとエラーになる
    p = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)]
    p[0] = p[1] = False
    p[2] = p[3] = p[5] = True
    for is1 in range(3, maxa2, 2):
        for is2 in range(is1 ** 2, maxa2, is1):
            p[is2] = False
    prime_list = [i for i, b in enumerate(p) if b]

    r = 1
    jo = []
    for pre in prime_list:
        if all([ae == 1 for ae in a]):
            break
        while True:
            c = [ae % pre == 0 for ae in a]
            if all(c):
                r *= pre
                a = [ae // pre for ae in a]
            else:
                if c.count(0) == 1:
                    r *= pre
                    jo.append(pre)
                    a[c.index(0)] *= pre
                    a = [ae // pre for ae in a]
                else:
                    break
    jo.sort()
    lenjo = len(jo)
    for joe in jo[:lenjo - 1]:
        r = r // joe
    print(r)

if __name__ == '__main__':
    main()