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 fractions

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

def method(number , List):
    newList = []
    answer = number
    for x in range(len(List)):
        test = fractions.gcd(number, List[x]) 
        if test == 1:
            newList.append(List[x])
        answer = min(answer, test)
    return answer , newList

def seachgcd(List):
    if List.count(1) > 1:
        return [1]
    newList = []
    for x in range(0, len(List) // 2, 2):
        number = fractions.gcd(List[x],List[x+1])
        newList.append(number)
    if len(List) % 2 == 1:
        newList.append(List[-1])
    return newList

def mainprogram(A, k=1):
    if len(A) == 2:
        return fractions.gcd(A[0], A[1])
    answer, newList = method(A[0], A)
    if len(newList) == 1:
        A.remove(newList[0])
        B = seachgcd(A) 
        answer = B[0]*k
        return answer
    elif len(newList) == 0:
        for x in range(len(A)):
            A[x] = A[x] // answer
        return mainprogram(A, answer)
    elif len(newList) == len(A)-1:
        A.remove(A[0])
        B = seachgcd(A) 
        answer = B[0]*k
        return answer
    else:
        answer1, newList1 = method(newList[0], newList)
        answer = fractions.gcd(answer1,answer)
        answer *= k
        return answer

print(mainprogram(A))

Submission status: Wrong Answer

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

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


n = int(input())

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

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

g = []
gg = []
ggg = []
gggg = []
for i in range(0, n):
    if i!=0: g.append(gcd(a[0], a[i]))
    if i!=1: gg.append(gcd(a[1], a[i]))
    if i!=2: ggg.append(gcd(a[2], a[i]))
    if n>=4 and i!=3: gggg.append(gcd(a[3], a[i]))


g.sort()
gg.sort()
ggg.sort()
if n>=4: gggg.sort()

g.pop(0)
gg.pop(0)
ggg.pop(0)
if n>=4: gggg.pop(0)

if n>=4:
    if g[0]==gg[0] and g[0]==ggg[0] and g[0]==gggg[0] : print(g[0])
    elif g[0]==gg[0] and g[0]==ggg[0]: print(g[0])
    elif g[0]==gg[0] and g[0]==gggg[0]: print(g[0])
    elif g[0]==ggg[0] and g[0]==gggg[0]: print(g[0])
    elif gg[0]==ggg[0] and ggg[0]==gggg[0]: print(gg[0])

else:
    if g[0]==gg[0] and g[0]==ggg[0] : print(g[0])
    elif g[0]==gg[0]: print(g[0])
    elif g[0]==ggg[0]: print(ggg[0])
    elif gg[0]==ggg[0]: print(gg[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
w=sorted(a)
ans=1
end=False

flag=False
for h in range(n):
    if a[h]%w[0]!=0 and flag==True:
       break
    if a[h]%w[0]!=0:
        flag=True
    if h==n-1:
        ans=w[0]
        end=True
"""
y=10000000001
for i in range(n):
    y=min(y,a[i]//2)
"""
    

for i in reversed(range(2,-(-w[0]//2)+2)):
    flag=False
    if end==True:
        break
    for h in range(n):
        if a[h]%i!=0 and flag==True:
            break
        if a[h]%i!=0:
            flag=True
        if h==n-1:
            ans=i
            end=True
            break
print(ans)

Submission status: Wrong Answer

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

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

fort = [nums[0], gcd(nums[0], nums[1])]
back = [nums[N-1], gcd(nums[N-1], nums[N-2])]
ans = []

for i in range(N-2):
    fort.append(gcd(fort[i+1], nums[i+2]))
                
for i in range(N-2):
    back.append(gcd(back[i+1], nums[i+2]))
    
for i in range(1, N-1):
    ans.append(gcd(fort[i-1], back[N-1-i]))

ans.append(fort[N-1])
ans.append(back[N-1])

print(max(ans))

Submission status: Wrong Answer

Solution code:
import copy

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

if N % 2 > 0:
    N += 1
    A.append(A[-2])

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

gcd_array = []
min_gcd = 10**9 + 1
min_idx = -1
min_val1 = 0
min_val2 = 0
for i in range(0, int(0.5*N)):
    val = gcd(A[2*i], A[2*i+1])
    gcd_array.append(val)
    if val < min_gcd:
        min_gcd = val
        min_idx = len(gcd_array)-1
        min_val1 = A[2*i]
        min_val2 = A[2*i+1]

gcd_array2 = copy.deepcopy(gcd_array)

gcd_array[min_idx] = min_val1
gcd_array2[min_idx] = min_val2

val1 = gcd_array[0]
val2 = gcd_array2[0]
for i in range(1, len(gcd_array)):
    val1 = gcd(gcd_array[i], val1)
    val2 = gcd(gcd_array2[i], val2)

if val1 > val2: print val1
else: print val2

Submission status: Wrong Answer

Solution code:
# coding: utf-8

from functools import reduce
import copy
import fractions

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

default_gcd = reduce(fractions.gcd, integers)
change_to = filter(lambda x: x >= default_gcd, integers)

gcds = []

for i in range(N):
    orig = integers[i]
    for x in change_to:
        integers[i] = x
        gcds.append(reduce(fractions.gcd, integers))
    integers[i] = orig
print(max(gcds))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

mA=min(A)
xA=sorted([(gcd(mA, a), a) for a in A])

zA=[z[1] for z in xA[1:]]
print(reduce(gcd, zA))

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 1
odd = 0
even = 0
for a in As:
    if a%2 == 0:
        even += 1
    else:
        odd += 1
if even >= 2 and odd >= 2:
    print(1)
elif even == 1:
    c = 0
    for b in As:
        if b % 2 == 1:
            c = b
            break
    for a in As:
        if a % 2 == 1:
            c = fractions.gcd(c, a)
    print(c)
elif odd == 1:
    c = 0
    for b in As:
        if b % 2 == 0:
            c = b
            break
    for a in As:
        if a % 2 == 0:
            c = fractions.gcd(c, a)
    print(c)
    
else:
    
    for i in range(N):
        flag = True
        if i == 0:
            a = As[1]
        else:
            a = As[0]
        for j in range(N):
            if j != i:
                a = fractions.gcd(a, As[j])
                if a <= ans:
                    flag = False
                    break
        if flag:  
            ans = a
    print(ans)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N-1):
    if N == 1 : 
      tmp = A[0]
    elif N == 2 :
      tmp = functools.reduce(fractions.gcd, A)
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from itertools import combinations
from functools import reduce
import random


N = int(input())
a_set = set(map(int, input().split()))

origina_gcd = reduce(gcd, a_set)

n_1_combis = combinations(a_set, N - 1)

max_gcd = origina_gcd
for combi in n_1_combis:
    tmp_gcd = reduce(gcd, combi)
    max_gcd = max(max_gcd, tmp_gcd)
print(max_gcd)

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
if n==2:
    print(max(a[0],a[-1]))
    exit()
#mae
r1=a[0]
flag1=0
for i in range(1,n):
    x=fractions.gcd(r1,a[i])
    if x<r1 and flag1==0:
        print(114514)
        if i!=1:
            flag1=1
        else:
            r1=x
    elif x<r1:
        r1=x
#usiro
r2=a[n-1]
flag2=0
for k in range(1,n):
    y=fractions.gcd(r2,a[n-k-1])
    if y<r2 and flag2==0 :
        if k!=1:
            flag2=1
        else:
            r2=y
    elif y<r2:
        r2=y
p=a[0]
a[0]=a[1]
a[1]=p
q=a[n-1]
a[n-1]=a[n-2]
a[n-2]=q
#mae
r3=a[0]
flag3=0
for v in range(1,n):
    x=fractions.gcd(r3,a[v])
    if x<r3 and flag3==0:
        if v!=1:
            flag3=1
        else:
            r3=x
    elif x<r3:
        r3=x
#usiro
r4=a[n-1]
flag4=0
for w in range(1,n-1):
    y=fractions.gcd(r4,a[n-w-1])
    if y<r4 and flag4==0:
        if w!=1:
            flag4=1
        else:
            r4=y
    elif y<r4:
        r4=y
print(max(r1,r2,r3,r4))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
i = 2
p = [2]
while(max(a) >= i):
    if len([x%i for x in a if x%i != 0]) > 1:
        p.append(i)
        isObvious = True
        while(isObvious):
            i += 1
            isObvious = False
            for k in p:
                if i % k == 0:
                    isObvious = True
                    break
    else:
        ans = ans * i
        a = [int(x/i) if x%i == 0 else 1 for x in a]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
import fractions
import sys
if N == 2:
    print(fractions.gcd(A[0],A[1]))
    sys.exit()

f1=fractions.gcd(A[0],A[1])
f2=fractions.gcd(A[1],A[2])
f3=fractions.gcd(A[2],A[0])

f_list = [f1,f2,f3]
if N <= 3:
    print(max(f_list))
    
if f_list.count(max(f_list)) ==1:
    count_left = 0
else:
    count_left = 1
count_left

import numpy as np
if list((np.array(A[3:])/max(f_list) == np.array(A[3:])//max(f_list))*1).count(0) ==0:
    print(max(f_list))
elif list((np.array(A[3:])/max(f_list) == np.array(A[3:])//max(f_list))*1).count(0) ==1 and count_left ==1:
    zero_index = list((np.array(A[3:])/max(f_list) == np.array(A[3:])//max(f_list))*1).index(0)
    if list(np.array(A[3:])/A[3:][zero_index] == np.array(A[3:])//A[3:][zero_index]).count(0)==0:
        print(A[3:][zero_index])
    else:
        print(max(f_list))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
N = int(input())
A = [int(i) for i in input().split()] 
max_gcd = functools.reduce(fractions.gcd, A)
for i in range(1, N):
	tmp = A.copy()
	tmp.pop(i)
	gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd
print(max_gcd)

Submission status: Wrong Answer

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

D = {}

def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2   
    if n != 1: a.append(n)
    #Only odd number is possible
    return a

for i in range(N) :
    L = trial_division(A[i])
    SET = list(set(L))
    for l in SET :
        if l not in D :
            D[l] = [L.count(l)]
        else :
            D[l].append(L.count(l))


ans = 1
for element in D :
    D[element] = sorted(D[element])
    if len(D[element]) <= N-2 :
        continue
    elif len(D[element]) == N-1 :
        ans *= (element ** D[element][0])
    else : #len(D[element]) == N :
        if D[element][0] == D[element][1] :
            ans *= (element ** D[element][0])
        elif N >= 3 :
            ans *= (element ** D[element][1])
        else :
            ans *= (element ** D[element][0])
    #print(ans)
#print(D)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

mA=max(A)
xA=sorted([(gcd(mA, a), a) for a in A])

zA=[z[1] for z in xA[1:]]
print(reduce(gcd, zA))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = min(A)
tmp = 1
for i in reversed(range(2,M+1)):
    count = 0
    memo = 0
    for j in range(N):
        if A[j]%i != 0:
            count += 1
            memo = j
            if count > 1:
                break
    if count <= 1:
        tmp = i
        break
print(tmp)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = il()
    ans = 0
    tmp = {}
    for i, n in enumerate(combinations(A, N - 1)):
        ans = max(ans, reduce(gcd, n))
        try:
            tmp[max(ans, reduce(gcd, n))] += 1
            return ans
        except KeyError:
            tmp[max(ans, reduce(gcd, n))] = 0
    return ans


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

Submission status: Wrong Answer

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

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

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

a=A[0]
idx=1
for i in range(1, N):
    b=gcd(a, A[i])
    if b<a:
        a=b
        idx=i

B=A[:]
B.pop(idx)
ans1=gcd_list(B)
B=A[:]
B.pop(idx-1)
ans2=gcd_list(B)
print(max(ans1, ans2))

Submission status: Wrong Answer

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

from fractions import gcd
from functools import reduce
import functools

def gcd(a,b):
    if a==0:
        return b 
    else:
        return gcd(b%a,a)
  
max_gcd = 0
loop_range = min(10,len(A))

# 小さい方から確認
for i in range(loop_range):
  if i < N:
    values = A[i+1:] + A[:i] 
  else:
    values = A[:-1]
  
  g = lambda a,b:a if b==0 else g(b,a%b)
  gcd = functools.reduce(lambda x,y:g(x,y),values)
  max_gcd = max(max_gcd,gcd)

# 大きい方からも確認
A.sort(reverse=True)
for i in range(loop_range):
  if i < N:
    values = A[i+1:] + A[:i] 
  else:
    values = A[:-1]
  
  g = lambda a,b:a if b==0 else g(b,a%b)
  gcd = functools.reduce(lambda x,y:g(x,y),values)
  max_gcd = max(max_gcd,gcd)

print(max_gcd)

Submission status: Wrong Answer

Solution code:
# C - GCD on Blackboard
import sys

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

def gcd(a, b):
	m = max(a, b)
	n = min(a, b)
	while True:
		if n==0:
			return m
		else:
			_=m%n
			m=n
			n=_

if len(n_list)==2:
	gcd_ = gcd(n_list[0], n_list[1])
	print(gcd_)
	sys.exit()
	
gcd_ = 0
for i in range(n):
	pop_ = n_list.pop(i)
	gcd_min = min([gcd(n_list[j], n_list[j+1]) for j in range(len(n_list)-1)])
	n_list.insert(i, pop_)
	gcd_ = max(gcd_, gcd_min)	

print(gcd_)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

div = defaultdict(int)
for a in set(A):
    divisor = make_divisors(a)
    for d in divisor:
        div[d] += 1

N = len(set(A))
for num, a in sorted(div.items(), reverse=True):
    if a > N - 2:
        print(num)
        exit()

Submission status: Wrong Answer

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

def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=sorted(spaceinput(),reverse=True)


notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=rewrite[0]=best[0]=a[0]
for i in range(1,N):

    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([rewrite[i],gcd(a[i],best[i-1])])
    #print([notrewrite[i],rewrite[i]])


if N==2:
    print(max(a))
else:
    print(best[N-1])

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
A = list(map(int, 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(reverse=True)
    return divisors
A.sort(reverse=True)
all_lst = []
for i in A:
  lst = make_divisors(i)
  all_lst.append(lst)
max = 1
for v in itertools.permutations(all_lst, 2):
    num = list(set(v[0]) & set(v[1]))[-1]
    if (num > max):
      max = num
print(max)

Submission status: Wrong Answer

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

for val in A:
    if val%A[0] == 0:
        continue
    else:
        break
else:
    print(A[0])
    exit()

ngcnt = 0
bef_searchnum = A[0] // 2
searchnum = A[0] // 2
resultflg = False
initflg = True
while 1:
    bef_searchnum = searchnum
    if initflg:
        initflg = False
    else:
        if resultflg:
            searchnum = searchnum + (A[0] - searchnum) // 2
        else:
            searchnum = searchnum // 2
    for val in A:
        if val%searchnum == 0:
            continue
        elif ngcnt < 2:
            ngcnt += 1
            continue
        else:
            if resultflg:
                print(bef_searchnum)
                exit()
            resultflg = False
            break
    else:
        resultflg = True

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

maxv = 0
N = int(input())
Value = list(map(int,input().split()))

base = gcd_list(Value)

for i in range(N):
    if is_prime(int(Value[i] / base)):
        del Value[i]
        break
        
print(gcd_list(Value))

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:
            tmp =1
            break
        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:
            tmp2 =1
            break
        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:
            tmp3 =1
            break
        else:
            flag = True
print(max(tmp, tmp2, tmp3))

Submission status: Wrong Answer

Solution code:

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

def factorize(n):
    nn = n
    lst = []
    for i in range(2, int(1 + n ** 0.5)):
        k = 0
        while nn % i == 0:
            k += 1
            nn = nn // i
        if k > 0:
            lst.append([i, k])
    if nn != 1:
        lst.append([nn, 1])
    return lst

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

for a in A:
    factorize(a)

Submission status: Wrong Answer

Solution code:
import fractions as f
import heapq
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)
    mins = heapq.nsmallest(2, new_As)
    if len(new_As) == 1:
        ans = max(ans, mins[0])
    else:
        ans = max(ans, f.gcd(mins[0], mins[1]))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,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
  
y = []
for i in range(n):
  y.append(make_divisors(a[i]))

list = [x for list in y for x in list]
dub = set([x for x in list if list.count(x) > 1])
#print(y)
print(max(dub))

Submission status: Wrong Answer

Solution code:
import fractions

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

def method(number , List):
    newList = []
    answer = number
    for x in range(len(List)):
        test = fractions.gcd(number, List[x]) 
        if test == 1:
            newList.append(List[x])
        answer = min(answer, test)
    return answer , newList

def seachgcd(List):
    if List.count(1) > 1:
        return [1]
    newList = []
    for x in range(0, len(List) // 2, 2):
        number = fractions.gcd(List[x],List[x+1])
        newList.append(number)
    if len(List) % 2 == 1:
        newList.append(List[-1])
    return newList

def mainprogram(A, k=1):
    if len(A) == 2:
        return fractions.gcd(A[0], A[1])
    answer, newList = method(A[0], A)
    if len(newList) == 1:
        A.remove(newList[0])
        B = seachgcd(A) 
        answer = B[0]*k
        return answer
    elif len(newList) == 0:
        for x in range(len(A)):
            A[x] = A[x] // answer
        return mainprogram(A, answer)
    elif len(newList) == len(A)-1:
        A.remove(A[0])
        B = seachgcd(A) 
        answer = B[0]*k
        return answer
    else:
        answer1, newList1 = method(newList[0], newList)
        answer = fractions.gcd(answer1,answer)
        return answer

print(mainprogram(A))

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)

min2A = A[A.argsort()[1]]
minA = np.amin(A)
if np.sum((A%min2A)==0)>=N-1:
    print(min2A)
elif np.sum((A%minA)==0)>=N-1:
    print(minA)
else:
    #for i in range((min2A//2)+1)[::-1]:
    #    if np.sum((A%i)==0)>=N-1:
    #        print(i)
    #        break
    for i in range(1,min2A):
        if (min2A%i == 0) or (minA%i == 0):
            if(min2A%i == 0):
                j = int(min2A/i)
            elif(minA%i == 0):
                j=int(minA/i)
            if np.sum((A%j)==0)>=N-1:
                print(j)
                break

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)

    tt = [0, 0, 0]

    for i in range(n):
        if a[i] % l[0] != 0:
            tt[0] += 1

        if a[i] % l[1] != 0:
            tt[1] += 1

        if a[i] % l[2] != 0:
            tt[2] += 1

    for i in range(3):
        if tt[i] <= 1:
            print(l[i])
            exit()

    print(1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=list(set(A))
maxi=10**9
allyp=[]
for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5+1
    for j in range(1,int(a)+1):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(int(A[i]/j))
    A[i]=divesor
    allyp+=A[i]
    if maxi>int(max(A[i])):
        maxi=int(max(A[i]))
allyp=list(set(allyp))
allyp.sort(reverse=True)
for i in allyp:
    flag=1
    for j in range(len(A)):
        if i not in A[j]:
            flag-=1
    if flag >=0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
import math

# 整数xが素数かどうかを判定する
def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()

prime_cnt = 0
for i in range(N):
    if is_prime(A[i]):
        prime_cnt += 1
    if len(A) >= 3 and prime_cnt > 2:
        print(1)
        exit()


if N >= 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 = max(A[0], A[1])
        
print(gcd_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))

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

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

    
elif N==3:
    d=gcd(A[0],A[1])
    b=gcd(A[2],A[1])
    c=gcd(A[2],A[0])
    
    ans=max([d,b,c])
    print(d,b,c)



else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)

print(ans)

Submission status: Wrong Answer

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

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

X = []
for i in range(N):
  if i == N-1:
    X.append(gcd(A[0], A[i]))
  else:
    X.append(gcd(A[i], A[i+1]))
#print(X)
X.sort(reverse=True)
if len(X) < 3:
  print(X[0])
else:
  print(X[-3])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

data = {}


def gcv(a, b):
    global data
    # if a >= b:
    #     a, b = b, a
    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:
        # print(a, b)
        data['{}:{}'.format(a, b)] = gcv(b, a % b)

        return data['{}:{}'.format(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
    n_new = sorted(n_dict.items(), key=lambda x: x[1], reverse=True)
    if n_new[0][0] == 1:
        return n_new[1][0]
    return n_new[0][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:
import fractions, sys
from functools import reduce
 
def gcd(numbers) :
    return reduce(fractions.gcd, numbers)

def is_prime(q):
  q = abs(q)
  if q == 2: return True
  if q < 2 or q&1 == 0: return False
  return pow(2, q-1, q) == 1
  
N = int(input())
A = list(map(int, input().split()))

div = gcd(A)
for i in range(N) :
  if is_prime(int(A[i] / div)) :
    print(gcd(A[0:i] + A[i+1:N]))
    sys.exit()
print(div)

Submission status: Wrong Answer

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

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

valueList = [a[0]]
maxList = []

for i in range(n):
  g = a[0]
  for j in range(i):
    g = gcd(g,a[j])
  valueList.append(g)
  g = valueList[i]
  for k in range(i+1, n):
    g = gcd(g, a[k])
  maxList.append(g)
    
print(max(maxList))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(i) for i in input().split()]

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

flag = 0
ans = 1

d = [0 for _ in range(N//2)]

for i in range(N//2):
    d[i] = gcd(l[i*2],l[i*2+1])
if N%2 == 1:
    d.append(l[-1])

ans = 1
for j in range(N):
    p = j//2
    if j != N-1:
        if j%2 == 0:
            element = l[j+1]
        else:
            element = l[j-1]
    else:
        element = d[0]
    for i in range(len(d)):
        if i != p:
            element = gcd(d[i], element)
    ans = max(ans, element)
print(ans)

Submission status: Wrong Answer

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

ans = 0
N = int(input())
A = tuple(map(int,input().split()))
A2 = tuple(set(A))
Af = 0

if len(A2) <= 2:
    A2 = (A2[0],A2[0])

for S in range(len(A2)):
    for i in range(len(A2)):
        if S != i:
            Af = GCD(Af,A[i])
    ans = max(ans,Af)
    Af = 0


print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1
is_prime(5)

maxv = 0
N = int(input())
Value = list(map(int,input().split()))

base = gcd_list(Value)

for i in range(N):
    if is_prime(int(Value[i] / base)):
        del Value[i]
        break
        
print(gcd_list(Value))

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 = list(map(int, input().split()))
ans = []
for i in range(N-1):
    b = gcd(a_list[i], a_list[i+1])
    ans.append(b)
if N > 2:
    b = gcd(a_list[0], a_list[N-1])
    ans.append(b)
if N == 2:
    print(max(a_list))
else:
    ans.sort()
    j = 0
    for i in range(N,2):
        if ans[i] % ans[2] != 0:
            j = 1
    if j == 0:
        print(ans[2])
    else:
        print(ans[1])

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = [int(i) for i in input().split()]
gmax = 0

for i in range(n):
    for j in range(n-1):
        if j != i and j != i-1:
            rec = fractions.gcd(a[j], a[j+1])
            if gmax > rec:
                break
            else:
                gmax = rec
        elif j == i-1 and j < n-2:
            rec = fractions.gcd(a[j], a[j+2])
            if gmax > rec:
                break
            else:
                gmax = rec

if n == 1:
    gmax = a[0]
elif n == 2:
    gmax = a[0] if a[0] > a[1] else a[1]
print(gmax)