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:
import math
import functools
import fractions

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

if max(v) % 2 ==0:
	b = True
else:
	b = False
		
v.sort()

for index,_ in enumerate(v):
	if _  % 2 ==0:
		if not b:
			v[index] = v[-1]
			break
			
	else:
		if b:
			v[index] = v[-1]
			break
				
#ans = functools.reduce(math.gcd,v)
ans = v[0]
for i in range(1,len(v)):
	ans = fractions.gcd(ans, v[i])
	
print(ans)

Submission status: Wrong Answer

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


if N == 2:
    print(max(A[0], A[1]))
else:
    m = min(A)

    ans = -1
    for i in range(m+1, 1, -1):
        count = 0
        for n in range(N):
            if count > 1:
                break
            if A[n] % i != 0:
                count += 1
        if count <= 1:
            ans = i
            break

    print(ans)

Submission status: Wrong Answer

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

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

mm = 0
for i in range(N):
  for j in range(i+1,N):
    g = gcd(A[i],A[j])
    if mm < g:
      mm = g
    else:
      break
    #print(i,j,g)
    
print(mm)

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
A.sort()
ans = 1000000000
Al = []
if len(A) >= 4:
    for lop in range(1,len(A),2):
        print(A[lop-1],A[lop])
        Al.append( fractions.gcd(A[lop-1],A[lop]) )
    if len(A) %  2 == 1:
        Al.append( fractions.gcd(A[len(A)-2],A[len(A)-1]) )
    Al.sort()
    print(Al[1])
elif len(A) == 3:
    A1 = fractions.gcd(A[0],A[1])
    A2 = fractions.gcd(A[0],A[2])
    A3 = fractions.gcd(A[1],A[2])
    print(max(A1,A2,A3))
else:
    print(max(A))

Submission status: Wrong Answer

Solution code:
def main() -> None:
    N = int(input())
    A = [int(x) for x in input().split()]
    A.sort(reverse=True)
    m = 0
    for i in range(N - 2):
        t = A[i] - A[i + 2]
        if t > m:
            m = t
    if m == 0:
        m = max(A)
    print(m)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import fractions
N=int(input())
As=list(map(int, input().split()))
ls=list(itertools.combinations(As,N-1))

def gcd(ls):
    n=len(ls)
    a=fractions.gcd(ls[0],ls[1])
    for i in range(2,len(ls)):
        a=fractions.gcd(a,ls[i])
    return a
now=0

if N == 2:
    now = fractions.gcd(As[0],As[1])
else:
    for i in range(len(ls)):
        if gcd(ls[i]) > now:
            now = gcd(ls[i])
        
print(now)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

from functools import reduce
def pair_gcd(a,b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        c = a % b
        return pair_gcd(b, c)
def gcd(numbers):
    return reduce(pair_gcd, numbers)

max_gcd = 1
for idx in range(N):
    remove_target = A_list.pop(0)
    if idx == 0:
        max_gcd = gcd(A_list)
        A_list.append(remove_target)
    else:
        if remove_target == max_gcd or pair_gcd(remove_target, A_list[0]) == max_gcd:
            gcd_value = gcd(A_list)
            A_list.append(remove_target)
            if max_gcd < gcd_value:
                max_gcd = gcd_value

        else:
            continue

print(max_gcd)

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:
import fractions
from functools import reduce


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

    # ans = tle_solver(A)
    ans = ac_solver(A)
    print(ans)


def ac_solver(A):
    a_min = min(A)
    a_min_divisors = sorted(make_divisors(a_min), reverse=True)
    for d in a_min_divisors:
        ct = 0
        for a in A:
            if a % d != 0:
                ct += 1

            if 2 < ct:
                break

        if ct == 1 or ct == 0:
            break

    return d


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

    return divisors


def tle_solver(A):
    gcds = [-1] * len(A)
    for idx in range(len(A)):
        tmp = A[:idx] + A[idx+1:]
        gcds[idx] = gcd(*tmp)

    return max(gcds)


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy
import math
from functools import reduce

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

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

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n = int(input())
a = list(map(int, input().split()))
a.sort()
rtn = gcd_list(a)
if rtn == 1:
    for x in a:
        if is_prime(x):
            a.remove(x)
            break
    rtn = gcd_list(a)
    print(rtn)
else:
    a_2 = [x / rtn for x in a]
    for x in a_2:
        if is_prime(x):
            a_2.remove(x)
            break
    rtn_2 = gcd_list(a_2)
    print(int(rtn * rtn_2))

Submission status: Wrong Answer

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

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

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

gcds = []

for i in range(n):
	temp = copy(a)
	temp.pop(i)

	num1 = temp[0] 
	num2 = temp[1] 
	result = gcd(num1, num2) 
  
	for i in range(2, len(temp)): 
	    result = gcd(result, temp[i]) 

	gcds.append(result)
      
gcds = list(set(gcds))
if len(gcds)==1:
	print(gcds[0])
else:
	gcds = sorted(gcds)
	print(gcds[1])

Submission status: Wrong Answer

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

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

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

p1,p2,p3 = gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[0],a[2])

p = [p1,p2,p3]

f = 0
tmp = a[0]
res1,res2,res3 = p1,p2,p3

for i in range(n):
    if gcd(tmp,a[i])==1:
        f += 1
    else:
        tmp = gcd(tmp,a[i])

    if i>=3:
        res1 = gcd(res1,a[i])
        res2 = gcd(res2,a[i])
        #res3 = gcd(res3,a[i])

    if f > 1:
        print(1)
        break
else:
    #print(tmp)
    print(max(tmp,res1,res2))

Submission status: Wrong Answer

Solution code:
import fractions as f
N = int(input())
As = list(map(int, input().split()))
ans = 1

for i in range(N):
    new_As = As.copy()
    new_As.pop(i)
    new_As = sorted(new_As)
    if len(new_As) == 1:
        ans = max(ans, new_As[0])
    else:
        ans = max(ans, f.gcd(new_As[0], new_As[1]))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A_array = list(map(int, input().split()))

if N == 2:
    print(max(A_array[0], A_array[1]))
    exit()

for i, A in enumerate(A_array):
    if i == 0:
        gcd_max = A

        remove_index = 0
        continue
    gcd = fractions.gcd(gcd_max, A)
    if gcd_max > gcd:
        gcd_max = gcd
        remove_index = i
# print(gcd_max, remove_index)

if remove_index <= 1:
    gcd_ans = 0
    for i, A in enumerate(A_array):
        if i <= 1:
            continue
        if i == 2:
            gcd_ans = A
            continue
        gcd_ans = fractions.gcd(gcd_ans, A)
    gcd_ans = max(
        fractions.gcd(gcd_ans, A_array[0]), fractions.gcd(gcd_ans, A_array[1]))
    print(gcd_ans)
else:
    gcd_ans = 0
    for i, A in enumerate(A_array):
        if i == 0:
            gcd_ans = A
            continue
        if i == remove_index:
            continue
        gcd_ans = fractions.gcd(gcd_ans, A)
    print(gcd_ans)

Submission status: Wrong Answer

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


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

def main():
    n = int(input())
    A = [int(e) for e in input().split(" ")]

    max_n = 0
    for i in range(n):
        if i < max_n:
            continue
        for j in range(i+1, n):
            current = gcd(A[i], A[j])
            if max_n < current:
                max_n = current

    if max_n == 0:
        max_n = 1000000000
    print(max_n)

main()

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
	divisors = []
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n//i)
	divisors.sort(reverse=True)
	return divisors

n = int(input())
a = list(map(int,input().split()))
a.append(0)
a.append(0)
a.sort(reverse=True)
ans1 = 0
ans2 = 0
ans3 = 0

result = make_divisors(a[0] - a[2])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if((j != 1) & (a[j] % result[i] != 0)):
			next = 1
			break
	if(next == 0):
		ans1 = result[i]
		break

result = make_divisors(a[0] - a[1])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if((j != 2) & (a[j] % result[i] != 0)):
			next = 1
			break
	if(next == 0):
		ans2 = result[i]
		break

result = make_divisors(a[1] - a[2])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if((j != 0) & (a[j] % result[i] != 0)):
			next = 1
			break
	if(next == 0):
		ans3 = result[i]
		break
max = ans1
if(ans2 > max):
	max = ans2
if(ans3 > max):
	max = ans3
print(max)

Submission status: Wrong Answer

Solution code:

def gcd(a, b):
    while a>0 and b >0:
        if a > b:
            a %= b
        else:
            b %= a
    return a + b

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

forwards = [A[0]]
backwards = [A[-1]]
for i in range(N):
    forwards.append(gcd(forwards[-1], A[i]))
    backwards.append(gcd(backwards[-1], A[-(i+1)]))
backwards = list(reversed(backwards))

ans = 0
for i in range(1, N-1):
    a = gcd(forwards[i-1], backwards[i+1])
    if a > ans:
        ans = a

if N > 2:
    ans = max([ans, forwards[-2], backwards[1]])
elif N == 2:
    ans = gcd(A[0], A[1])
else:
    ans = A[0]

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(m, n):
    x = max(m , n)
    y = min(m, n)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z

N = int(input())
a = list(map(int, input().split()))
d= list(range(0, N))
for i in range(0, N):
    l = 0
    if i == 0:
        c = gcd(a[1],  a[1])
    else:
        c = gcd(a[0], a[0])
    while l < N :
        if l != i:
            d[i] = gcd(c, a[l])
            l += 1
        else:
            l += 1
print(max(d))

Submission status: Wrong Answer

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

num = 0


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


for i in range(N):
    try:
        if A[i]%num == 0:
            continue
    except:
        pass
    B = A[:]
    B.pop(i)
    gcd1 = int(B[0])

    for j in range(1, N - 1):
        gcd1 = gcd(gcd1, B[j])

    if num < gcd1:
        num = gcd1

print(num)

Submission status: Wrong Answer

Solution code:
import fractions

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

ag0 = fractions.gcd(A[0], A[1])
ag1 = {A[0]}
ag1.add(A[1])

for d in A[2:]:
    ag1.add(ag0)
    ag0 = fractions.gcd(ag0, d)
    ag2 = set()
    for c in ag1:
        ag2.add(fractions.gcd(c, d))
    ag1 = ag2

print(max(ag1))

Submission status: Wrong Answer

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

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

mm = 0
for i in range(N):
  for j in range(i+1,N):
    g = gcd(A[i],A[j])
    if mm < g:
      mm = g
    else:
      break
    print(i,j,g)
    
print(mm)

Submission status: Wrong Answer

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


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


def gcda(a):
    ret = a[0]
    for i in range(1, len(a)):
        ret = gcd(ret, a[i])
    return ret


a = A
while len(a) > 5:
    m = len(a) // 2
    gcdl = gcda(a[:m])
    gcdr = gcda(a[m:])
    if gcdl < gcdr:
        a = a[:m] + [gcdr]
    else:
        a = [gcdl] + a[m:]

ans = 1
for i in range(0, len(a)):
    s = a[:i] + a[i+1:]
    ans = max(ans, gcda(s))

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import log
n = int(input())
a_array = sorted([int(x) for x in input().split()])
if len(set(a_array)) <=2:
    print(max(a_array))
    exit()

tmp = gcd(a_array[0], a_array[1])
flag = False
for i in a_array[2:]:
    if gcd(tmp, i) > 1:
        tmp = gcd(tmp, i)
    else:
        if flag:
            print(1)
            exit()
        else:
            flag = True
tmp2 = gcd(a_array[1], a_array[2])
flag = False
for i in a_array[2:]:
    if gcd(tmp2, i) > 1:
        tmp2 = gcd(tmp2, i)
    else:
        if flag:
            print(1)
            exit()
        else:
            flag = True
tmp3 = gcd(a_array[0], a_array[2])
flag = False
for i in a_array[2:]:
    if gcd(tmp3, i) > 1:
        tmp3 = gcd(tmp3, i)
    else:
        if flag:
            print(1)
            exit()
        else:
            flag = True
print(max(tmp, tmp2, tmp3))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import random
import copy

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

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

if n < 100:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in range(100):
    t = gcd(random.sample(a, 50))
    if ans < t:
      ans = t

print(ans)

Submission status: Wrong Answer

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

n = int(input())
an = [int(i) for i in input().split(" ")]
an = sorted(an)
if len(an) <= 2:
    print(max(an))
else:
    sample = []
    for i in range(len(an)):
        a1 = an[i]
        for a2 in an[i+1:]:
            tmo = gcd(a1, a2)
            if len(sample) == n:
                sample.sort()
                sample[-1] = min(sample[-1], tmo)
            else:
                sample.append(tmo)

    print(sample[-1])

Submission status: Wrong Answer

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


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

g_left = [a[0]]
g_right = [a[-1]]

for i in range(N):
    g_left.append(gcd(g_left[-1], a[i]))

for i in range(N - 1, -1, -1):
    g_right.append(gcd(g_right[-1], a[i]))

g_right.reverse()

# print(a)
# print(g_left)
# print(g_right)

g_left = g_left[1:]
g_right = g_right[:-1]

g = 1


for i in range(1, N-1):
    g = max(g, gcd(g_left[i-1], g_right[i+1]))
g = max(g, g_left[N - 1])
g = max(g, g_right[1])

print(g)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()

res = []

if N == 1:
    print(10**9)
else:
    for i in range(N):

        if len(A) >= 3:
            gcd_num = max(fractions.gcd(A[0], A[1]), fractions.gcd(A[0], A[2]), fractions.gcd(A[1], A[2]))
        else:
            gcd_num = fractions.gcd(A[0], A[1])
        res.append(gcd_num)
        
    print(max(res))

Submission status: Wrong Answer

Solution code:
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
C = [i for i in A]
def gcd(a, b): # 最大公約数
    a = abs(a)
    b = abs(b)
    while b:
        a, b = b, a % b
    return a
g0 = reduce(gcd,A[1:])
now = A[0]
id = 0

for i in range(1,N):
    ne = gcd(now,A[i])
    if ne < now:
        id = i
        now = ne
A.pop(id)

g1 = reduce(gcd,A)
now1 = C[N-1]
id1 = N-1
for i in reversed(range(0,N-1)):
    ne1 = gcd(now1,C[i])
    if ne1 < now1:
        id1 = i
        now1 = ne1
C.pop(id1)
g2 = reduce(gcd,C)
print(max(g1,g0,g2))

Submission status: Wrong Answer

Solution code:
import fractions
import functools
n = input()
lists = list(map(int, input().split()))
gcd1 = functools.reduce(fractions.gcd, lists)
i=1
y=1
judge = "true"
limit = min(lists)
#print(limit)
while i < limit:
  for index,list in enumerate(lists):
    if (list % i) != 0:
      lists[index] = limit
      judge = "false"
      break
  if judge == "false":
    break
  i += 1
#print(lists)
gcd2 = functools.reduce(fractions.gcd, lists)
if gcd1 >= gcd2:
  print(gcd1)
else:
  print(gcd2)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def gcd_list(numbers):
    return reduce(gcd, numbers)
n = ni()
a = nl()
minn = 10 ** 9 + 1
idx = -1
for i in range(n - 1):
    if minn >= gcd(a[i], a[i + 1]):
        minn = gcd(a[i], a[i + 1])
        idx = i
gcd1 = 0
gcd2 = 0
for i in range(n):
    if i != idx:
        gcd1 = gcd(gcd1, a[i])
    if i != idx + 1:
        gcd2 = gcd(gcd2, a[i])

print(max(gcd1, gcd2))

Submission status: Wrong Answer

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

def getNum(a, b):
    if a == b:
        return a
    while(True):
        a, b = max(a, b), min(a, b)
        a -= b
        if a == b:
            return a

ans = max(AList[0], AList[1])
if N == 3:
    ans = max(getNum(AList[0], AList[1]), getNum(AList[1], AList[2]), getNum(AList[2], AList[0]))
elif N > 3:
    ansA = getNum(AList[0], AList[1])
    ansB = getNum(AList[1], AList[2])
    ansC = getNum(AList[2], AList[3])
    ansD, ansE = AList[0], AList[3]
    aFlag, bFlag, cFlag, dFlag, eFlag = True, True, True, True, True
    for num in AList:
        if num % ansA != 0:
            if not aFlag:
                ansA = 1
            aFlag = False
        if num % ansB != 0:
            if not bFlag:
                ansB = 1
            bFlag = False
        if num % ansC != 0:
            if not cFlag:
                ansC = 1
            cFlag = False
        if num % ansD != 0:
            if not dFlag:
                ansD = 1
            dFlag = False
        if num % ansE != 0:
            if not eFlag:
                ansE = 1
            eFlag = False
    ans = max(ansA, ansB, ansC, ansD, ansE)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

set_ = set()
gcd_all = as_.pop()
for a in as_:
    set_ = set(gcd(s, a) for s in set_)
    set_.add(gcd_all)
    gcd_all = gcd(gcd_all, a)

print(max(set_))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

data = {}


def gcv(a, b):
    global data
    if data.get('{}:{}'.format(a, b), None):
        return data['{}:{}'.format(a, b)]
    elif data.get('{}:{}'.format(b, a), None):
        return data['{}:{}'.format(b, a)]

    if b == 0:
        data['{}:{}'.format(a, b)] = a
        return a
    else:
        return gcv(b, a % b)


def solve(n, a):
    if n == 2 and a[0] == a[1]:
        return a[0]
    n_dict = defaultdict(int)
    for i in range(len(a)):
        for j in range(len(list(a)) - i + 1):
            n_dict[gcv(a[i], a[j + i - 1])] += 1
    return sorted(n_dict.items(), key=lambda x: x[0])[1][0]


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def euclid(a, b):
    if a < b:
        tmp = a;
        a = b;
        b = tmp;

    r = a % b;
    while r != 0:
        a = b
        b = r
        r = a % b

    return b

if n == 2:
    print(max(a[0], a[1]))
    exit()
elif n == 3:
    print(max(euclid(a[0], a[1]), max(euclid(a[1], a[2]), euclid(a[0], a[2]))))
    exit()
else:
    t1 = euclid(a[0], a[1])
    t2 = euclid(a[1], a[2])
    t3 = euclid(a[0], a[2])

    l = [t1, t2, t3]
    l.sort(reverse=True)

    ans = l[0]
    flag = 0

    for i in range(3, n):
        if flag == 0 and a[i] % ans != 0:
            ans = l[1]
            flag = 1

        if flag == 1 and a[i] % ans != 0:
            ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import random
import copy

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

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

if n < 100:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in range(100):
    t = gcd(random.sample(a, 30))
    if ans < t:
      ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
 
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


n = 3
A = [12, 15, 18, 7]
#A = [100000,100000]


max_a = max(A)

divisors = make_divisors(max_a)

divisors = sorted(divisors, reverse = True)




previous_d=0
ans = 1
for d in divisors:
    #print(d)
    A_2 = [a/d for a in A]
    #print(A_2)
    num_float = 0
    for a in A_2:
        if a.is_integer() == False:
            num_float += 1
    #print(num_float)
    if num_float <= 1:
        ans = d
        break
    
        
print(ans)

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

A_gcd = gcd_list(A_list)
A_list = list(map(lambda x: x/A_gcd, A_list))
remove_index = 0
for i in range(N-1):
  a = fractions.gcd(A_list[i], A_list[i+1])
  if a==1 and i != 0:
    remove_index += i+1
    break;
  elif i == 0 and a==1 :
    if N == 2:
      remove_index += 0
      break;
    b = fractions.gcd(A_list[1], A_list[2])
    if b == 1:
      remove_index += 1
    else:
      remove_index += 0
    break;
A_list.pop(remove_index)
ans = gcd_list(A_list) * A_gcd
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
As=input().split()
A = np.array([int(s) for s in As])
del(As)
minA = np.amin(A)
for i in range(minA+1)[::-1]:
    if np.sum((A%i)==0)>=N-1:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys


def gcd(a, b):
    """Euclidean Algorithm"""
    while b != 0:
        a, b = b, a % b
    return a


def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    if N == 2:
        return max(A)

    g = A[0]
    B = []
    for a in A:
        g = gcd(a, g)
        B.append(g)

    i = B.index(g)
    A.pop(i)

    g = A[0]
    for a in A:
        g = gcd(g, a)

    return g


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

Submission status: Wrong Answer

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

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

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

p1,p2,p3 = gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[0],a[2])

p = [p1,p2,p3]

f = 0
tmp = a[0]
res1,res2,res3 = p1,p2,p3

for i in range(n):
    if gcd(tmp,a[i])==1:
        f += 1
    else:
        tmp = gcd(tmp,a[i])

    if i>=3:
        res1 = gcd(res1,a[i])
        res2 = gcd(res2,a[i])
        res3 = gcd(res3,a[i])

    if f > 1:
        print(1)
        break
else:
    print(tmp)
    #print(max(tmp,res1,res2,res3))

Submission status: Wrong Answer

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


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

n = int(input())

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

gcdf = gcd_core(a[0],a[1])

for i in range(n):
    if a[i] % gcdf == 0:
        continue
    else:
        gcdf = gcd_core(a[i],gcdf)

if n==2:
    print(max(a))
else:
    for i in range(n):
        a[i] = a[i]//gcdf
    kouho = a[0]
    count = 0
    for i in range(n):
        if a[i] % kouho != 0:
            temp = gcd_core(a[i],kouho)
            if temp == 1:
                count += 1
                if count > 1:
                    kouho = 1
                    break
                else:
                    continue
            else:
                kouho = temp
        else:
            continue
    kouho2 = a[1]
    count = 0
    for i in range(n):
        if a[i] % kouho2 != 0:
            temp = gcd_core(a[i], kouho2)
            if temp == 1:
                count += 1
                if count > 1:
                    kouho2 = 1
                    break
                else:
                    continue
            else:
                kouho2 = temp
        else:
            continue
    print(gcdf*max(kouho,kouho2))

Submission status: Wrong Answer

Solution code:
import fractions

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

kouho = [a[0]]

for i in range(n - 1):
    hoge = []
    for j in range(len(kouho)):
        hoge.append(fractions.gcd(a[i + 1], kouho[j]))

    if min(kouho) == max(hoge):
        kouho = [max(hoge)]
    elif len(hoge) == 1:
        kouho = [hoge[0], kouho[0]]
    else:
        kouho = hoge

a1 = max(kouho)

a[0], a[1] = a[1], a[0]

kouho = [a[0]]

for i in range(n - 1):
    hoge = []
    for j in range(len(kouho)):
        hoge.append(fractions.gcd(a[i + 1], kouho[j]))

    if min(kouho) == max(hoge):
        kouho = [max(hoge)]
    elif len(hoge) == 1:
        kouho = [hoge[0], kouho[0]]
    else:
        kouho = hoge

a2 = max(kouho)

print(max(a1, a2))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop
import queue
import re
import math
import functools
import numpy

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

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


N = int_raw()
As = ints_raw()


def main():
    if len(As)<=2:
        return max(As[0],As[1])
    
    gcds = [gcd(As[i-1],As[i]) for i in range(N)]
    argMgcd = numpy.argmin(gcds)
    
    rmngcd = functools.reduce(gcd, As[:argMgcd]+As[argMgcd+1:])
    
    lmpgcd = 0
    if argMgcd >0:
        lmpgcd = functools.reduce(gcd, As[:argMgcd-1]+As[argMgcd:])
    else:
        lmpgcd = functools.reduce(gcd, As[0:-1])
    return max(rmngcd,lmpgcd)


print(main())

Submission status: Wrong Answer

Solution code:

# C

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

# aをひとつをのぞいた中で最大公約数を求める
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

div = []
for i in range(n):
    div.append(set(make_divisors(a[i])))

ans_i = div[0]
for j in range(n):
    ans_i = ans_i & div[i]
ans = max(ans_i)

for i in range(n):
    if i != 0:
        ans_i = div[0]
    else:
        ans_i = div[1]
    for j in range(n):
        if i != j:
            ans_i = ans_i & div[j]
    if ans <= max(ans_i):
        ans = max(ans_i)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()

res = []

if N == 1:
    print(A[0])
else:
    for i in range(N):

        if len(A) >= 3:
            gcd_num = max(fractions.gcd(A[0], A[1]), fractions.gcd(A[0], A[2]), fractions.gcd(A[1], A[2]))
        else:
            gcd_num = fractions.gcd(A[0], A[1])
        res.append(gcd_num)
        
    print(max(res))

Submission status: Wrong Answer

Solution code:
def c():
    ans = 0
    N = long(raw_input())
    A = raw_input().split()
    for i in range(N):
        for j in range(i+1, N):
            C = long(A[i])
            D = long(A[j])
            #prlong "C:{}, D:{}".format(C,D)
            if C > D:
                g = gcd(C, D)
            else:
                g = gcd(D, C)
            if g > ans:
                ans = g
    print ans

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

def main():
    c()
	
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import random
import copy

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

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

if n < 100:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in range(100):
    t = gcd(random.sample(a, 20))
    if ans < t:
      ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

g = gcd(A[0], A[1])
lst = []
time = 0
lmax = 1
for i in range(2,N):
    cand = gcd(g, A[i])
    if cand < g:
        l = int(g / cand)
        g = cand
        if lmax < l:
            lmax = l
            time = 0
lst.append(g)
A = A[1:] + [A[0]]
g = gcd(A[0], A[1])
for i in range(2,N):
    cand = gcd(g, A[i])
    if cand < g:
        l = int(g / cand)
        g = cand
        if lmax < l:
            lmax = l
            time = 1
lst.append(g)
A = A[1:] + [A[0]]
g = gcd(A[0], A[1])
for i in range(2,N):
    cand = gcd(g, A[i])
    if cand < g:
        l = int(g / cand)
        g = cand
        if lmax < l:
            lmax = l
            time = 2
lst.append(g)
print(lst[time]*lmax)