Problem:


Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Wrong Answer

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

def getdiff(A, a_min):
  ret = []
  for a in A:
    d = a % a_min
    if d != 0:
      ret.append(d)
  ret.append(a_min)
  return(ret)

l = len(A)
while 2 <= l:
  a_min = min(A)
  A.remove(a_min)
  a_ret = min(A)
  A = getdiff(A, a_min)
  l = len(A)
#  print(":",A)

print(a_ret)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
'''Snippets for factorization.
Available functions:
- run_prime_factorization: Run prime factorization.
'''


def run_prime_factorization(max_number: int) -> dict:
    '''Run prime factorization.
    Args:
        max_number: Int of number (greater than 1).
    Returns:
        A dictionary's items ((base, exponent) pairs).
    Landau notation: O(log n)
    '''

    from math import sqrt

    ans = dict()
    remain = max_number

    for base in range(2, int(sqrt(max_number)) + 1):
        if remain % base == 0:
            exponent_count = 0

            while remain % base == 0:
                exponent_count += 1
                remain //= base

            ans[base] = exponent_count

    if remain != 1:
        ans[remain] = 1

    return ans


def main():
    from fractions import gcd

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

    for ai in a:
        p = run_prime_factorization(ai)

        for key, pi in p.items():
            if key not in d.keys():
                d[key] = 1
            else:
                d[key] += 1

    ans = 1

    for key, val in sorted(d.items(), key=lambda x: x[1], reverse=True):
        if val == 3:
            ans *= key
        elif val == 2:
            ans *= key
            break

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

    print(ans)


if __name__ == '__main__':
    main()

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)
    S += 1


print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
from copy import copy
def gcd_list(numbers):
    return reduce(gcd, numbers)
ans = 0
N = int(input())
A = [int(n) for n 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
div = make_divisors(max(A))
for d in div:
    for i in range(N):
        if A[i] % d != 0:
            A.pop(i)
            break
    else:
        continue
    break
print(gcd_list(A))

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

def gcd(A, B):
    if A < B:
        A, B = B, A
    if B == 0:
        return A
    else:
        return gcd(B, A%B)



if N == 2:
    print(max(a))
else:
    ans = 1
    for i, j, k in [(0, -1, 1), (1, -1, 0), (0, 1, -1)]:
        a[0], a[-1], a[1] = a[i], a[j], a[k]
        small = 1
        x = a[0]
        big = N - 2
        y = a[-1]

        while small < big:
            if gcd(a[small], x) < gcd(a[big], y):
                y = gcd(a[big], y)
                big -= 1
            else:
                x = gcd(a[small], x)
                small += 1
        ans = max(ans, gcd(x,y))


    print(ans)

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)):
        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:
def gcd(x, y):
    while (y != 0):
        x, y = y, x%y
    return (x)

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

result = 1000000000
a[0] = a[1]

for i in range(1):
    for j in range(i+1,n):
        if(a[i]>result):
            a[i]=result
        if(a[i] >= a[j]):
            result = gcd(a[i], a[j])
        elif(a[i] < a[j]):
           result = gcd(a[j], a[i])
        if (result == 1):
            break

print(result)

Submission status: Wrong Answer

Solution code:
from functools import reduce


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


N = int(input())
a_list = list(map(int, input().split()))
gcd_list = [a_list[-1]]
for idx in range(N - 2, 0, -1):
    gcd_list.append(gcd(gcd_list[N - 2 - idx], a_list[idx]))
max_gcd_a = gcd_list[-1]
gcd_list.append(1)
gcd_list.reverse()

for idx in range(1, N):
    if idx != 1:
        left_gcd = gcd(left_gcd, a_list[idx])
    else:
        left_gcd = a_list[0]
    right_gcd = gcd_list[idx]

    gcd_a = gcd(left_gcd, right_gcd)
    if max_gcd_a < gcd_a:
        max_gcd_a = gcd_a

print(max_gcd_a)

# どれか１つを除いた時の最大公約数で最大のもの

Submission status: Wrong Answer

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

## input num
#i = input()
#A, B, T = [int(x) for x in i.split()]

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

## debug
#print("debug:{}".format(gcd(max(A),min(A))))
#print(list(reversed(range(1, gcd(max(A),min(A))+1))))

X = 0
for i in reversed(range(1, gcd(max(A),min(A))+1)):
    count = 0
    for j in A:
        if (j % i) == 0:
            count += 1
    if count > len(A)-2:
        X = i
        break

print(X)

Submission status: Wrong Answer

Solution code:
import copy
 
inp = int(input())
v = [int(d) for d in input().split()]
cc = []
m = []
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
if len(v) == 2:
    s = gcd(v[0],v[1])
    print(s)
    exit()
 
for e in range(len(v)):
    dd = copy.deepcopy(v)
    del dd[e]
    cc.append(dd)
 
for q in cc: #q 1抜き
    s = q[0]
    for a in range(len(q) -1): 
        s = gcd(s,q[a+1])
    m.append(s)
m.sort()
 
print(m[-1])

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

A_list.append(A_list[0])

minValue = 999999999
secondValue = 999999999
secondCount = 0
thirdValue = 999999999

for i in range(N):
    v = A_list[i]
    w = A_list[i+1]
    result = gcd(v, w)
    if minValue > result:
        minValue = result
        minIndex = i
    elif secondValue > result:
        thirdValue = secondValue
        secondValue = result
        secondIndex = i
        secondCount = 1
    elif secondValue == result:
        secondCount += 1
    elif thirdValue > result:
        thirdValue = result

if len(A_list) == 3:
    ans = gcd(A_list[0], A_list[1])
elif secondCount == 1 and (abs(minIndex - secondIndex) == 1 or abs(minIndex - secondIndex) == N-1):
    ans = thirdValue
else:
    ans = secondValue

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = input()

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


if len(A) < 3:
    print(max(A))
    sys.exit()



min_0 = A[0]
min_1 = A[1]
min_2 = A[2]


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]





def kouyaku(x, y):
    min_num = min(x, y)
    for i in reversed(range(min_num + 1)):
        if x % i == 0 and y % i == 0:
            return i

def check(n):
    fail_count = 0
    for a in A:
        if a % n != 0:
            fail_count +=1
            if fail_count == 2:
                return False
    return True




kouyaku_01 = kouyaku(min_0, min_1)
kouyaku_12 = kouyaku(min_1, min_2)
kouyaku_02 = kouyaku(min_0, min_2)


ans = 1
if check(kouyaku_01):
    ans = max(ans, kouyaku_01)

if check(kouyaku_12):
    ans = max(ans, kouyaku_12)


if check(kouyaku_02):
    ans = max(ans, kouyaku_02)


print(ans)

Submission status: Wrong Answer

Solution code:
def hcf(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        temp = a % b
        a = b
        b = temp
    return a
def blackbord(n,a):
    return max(list(hcf(a[i],j) for i in range(len(a)) for j in a[0:i] + a[i + 1:]))
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

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:
def m(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


N = int(input())
A = list(map(int, input().split()))
AF = [1] * (N - 1)
AB = [1] * (N - 1)

AF[0] = A[0]
AB[0] = A[-1]
if N == 2:
    print(max(A))
else:
    for i in range(1, N - 1):
        AF[i] = m(A[i - 1], A[i])
        AB[i] = m(A[i - 1], A[- (i + 1)])

    L = max(AF[-1], AB[-1], max([m(AF[i], AB[N - 3 - i]) for i in range(N - 2)]))

    print(L)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
  
N= int(input())
A =list(map(int, input().split()))
A_2 =  list(set(A))
gcd = []
 
for i in range(len(A_2)):
  a = A_2[i]
  A_2[i] = 0
  gcd.append(reduce(fractions.gcd, A_2))
  A_2[i] = a
print(max(gcd))

Submission status: Wrong Answer

Solution code:
from collections import deque

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


import fractions
from functools import reduce

ans=0
proc=lambda x: reduce(fractions.gcd, x)
GCD_target=proc(A)
#print("GCD_target = {}".format(GCD_target))

for i in range(N):
   #copied_A = A[:]
   #remove=A.popleft()
   
   GCD_current= proc(A) #gcd_list(list(A))
   #A.append(remove)
   #print(GCD_current)
   ans=max(ans,GCD_current)

print(ans)

Submission status: Wrong Answer

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

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

A = sorted(A)

import fractions
dmin = []
dmax = []
mina = min(A)
maxa = max(A)
for i in range(N):
    dmin.append(fractions.gcd(mina,A[i]))
    dmax.append(fractions.gcd(maxa,A[i]))


dmin = sorted(dmin)
dmax = sorted(dmax)
if len(dmax) == 1:
    print(dmax[0])
    exit()

if dmax[0] != dmax[1]:
    if dmin[0] != dmin[1]:
        print(max(dmax[1],dmin[1]))
    else:
        print(max(dmax[1],dmin[0]))
else:
    if dmin[0] != dmin[1]:
        print(max(dmax[0],dmin[1]))
    else:
        print(max(dmax[0],dmin[0]))

Submission status: Wrong Answer

Solution code:
import math
 
l = list(map(int, input().split()))
max_gcd = 0
for n, _ in enumerate(l):
    sub = [v for i, v in enumerate(l) if i != n]
    if not sub:
        continue
    if len(sub) > 1:
        res = sub[0]
        for c in sub[1::]:
            res = math.gcd(res, c)
        sub[0] = res
    max_gcd = max(max_gcd, sub[0])
print(max_gcd)

Submission status: Wrong Answer

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

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

    # 他のAiにはあって、あるAiに唯一ない約数が答え
    
    candidates = []

    if N == 2:
        print(max(A[0], A[1]))
        return

    candidates = {}
    # まずは0番目の奴の候補を考える
    j = A[0]
    for i in range(1, A[0]+1):
        if i >= j:
            break
        if A[0]%i == 0:
            candidates[i] = 1
            j = A[0]//i
            candidates[j] = 1

    for key in candidates.keys():
        if A[1]%key != 0:
            candidates[key] -= 1

    j = A[1]
    for i in range(1, A[1]+1):
        if i >= j:
            break
        if A[1]%i == 0:
            if not i in candidates:
                candidates[i] = 0
            j = A[1]//i
            if not j in candidates:
                candidates[j] = 0

    import copy
    for i in range(2, N):
        copied_candidates = copy.deepcopy(candidates)
        for key in copied_candidates.keys():
            if A[i]%key == 0:
                pass
            else:
                candidates[key] -= 1
                if candidates[key] < 0:
                    candidates.pop(key)
    
    ans = 0
    for key in candidates.keys():
        ans = max(ans, key)
    
    print(ans)


    

if __name__ == "__main__":
    solve()

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_div = [make_divisors(a[i]) for i in range(n)]

flag=False

for i in range(10000000000):
    out = 0
    tmp = a_div[0][i]
    for j in range(n):
        if tmp not in a_div[j]:
            out += 1
    if out <= 1:
        break

print(tmp)

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=[]

list_koyaku2=[]
list_koyaku22=[]  

list_koyaku3=[]
list_koyaku33=[]  

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=A[0]
    c=A[1]
    d=A[2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
        
    for a in A:
        list_koyaku2.append(gcd(a,c))

    for a in list_koyaku2:
        list_koyaku22.append(gcd(a,d))
        
    for a in A:
        list_koyaku3.append(gcd(a,b))

    for a in list_koyaku2:
        list_koyaku33.append(gcd(a,d))    
        
    ans1=max(list_koyaku11)
    ans2=max(list_koyaku22)
    ans3=max(list_koyaku33)

    ans=max([ans1,ans2,ans3])
        


print(ans)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
As = [int(i) for i in input().split()]
A = copy.copy(As)
max_gcd = 0

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

for i in range (N):
    del (A[i])
    if len(A) == 1:
        max_gcd = A[0]
    else:
        for k in range (N-2):
            A[k+1] = gcd(A[k], A[k+1])
            if A[N-2] > max_gcd:
                max_gcd = A[N-2]
    A = copy.copy(As) 
        
print (max_gcd)

Submission status: Wrong Answer

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

def gcd(a):
    m = min(a)
    l = len(a)
    b = [0]*l
    checkEnd = True
    for i,c in enumerate(a):
        b[i] = (c-1)%m+1
        checkEnd = checkEnd and (b[i] == c)
    if checkEnd:
        return m
    return gcd(b)

ans = gcd(A)
ran = list(range(N))
random.shuffle(ran)
for i in ran:
    B = A[:]
    B.pop(i)
    m = gcd(B)
    if m>ans:
        ans = m
        break
print(ans)

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)])
	print(gcd_min)
	n_list.insert(i, pop_)
	gcd_ = max(gcd_, gcd_min)	

print(gcd_)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = min(A)
tmp = 0
for i in reversed(range(1,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:
N=int(input())
A=list(map(int,input().split()))
A.sort()
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
if N == 2:
    a=max(A)
    b=gcd(A[0],A[1])
    print(max(a,b))
else:
    rem=[0,0]
    ans=0
    for i in range(N-1):
        if i == 0:
            if A[0] == 1:
                ans=gcdlist(A)
                break
            else:
                kari=gcd(A[0],A[1])
                if kari == 1:
                    B=A[::]
                    C=A[::]
                    del B[i]
                    del C[i+1]
                    ans=max(gcdlist(B),gcdlist(C))
                    break
                else:
                    A[1]=kari
        else:
            kari=gcd(A[i],A[i+1])
            if kari < A[i]:
                if kari != 1:
                    rem=[kari,i+1]
                else:
                    B=A[::]
                    C=A[::]
                    del B[i]
                    del C[i+1]
                    ans=max(gcdlist(B),gcdlist(C))
                    break
            else:
                A[i+1]=kari
    D=A[::]
    del D[1]
    ans2=gcdlist(D)
    if ans == 0:
        E=A[::]
        del E[rem[1]]
        ans=gcdlist(E)
    print(max(ans,ans2))

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
 
A.sort(reverse=True)
v1 = A[0]
count1 = 0
for i in range(N):
    tmp1 = v1
    v1 = gcd(v1, A[i])
    if  v1 == 1:
        count1 += 1
        if count1 == 1:
            v1 = tmp1
        
        
v2 = A[1]
count2 = 0
for i in range(N):
    tmp2 = v2
    v2 = gcd(v2, A[i])
    if v2 == 1:
        count2 += 1
        if count2 == 1: 
            v2 = tmp2

if N != 2:
    s1 = 1
    s2 = 1
    if count1 == 1 and v1 <= 10 ** 9:
        s1 = v1
    if count2 == 1 and v2 <= 10 ** 9:
        s2 = v2
    print(tmp * max(s1, s2))
else:
     print(tmp * min(v1, v2))

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
if __name__ == '__main__':
  n = input()
  n_list = input().split(' ')
  n_list = map(int, n_list)
  
  print(gcd_list(n_list))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:01:24 2019
ABC125C
@author: maezawa
"""

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
a0 = a[0]
mingcd = a0
min0 = 0
for i in range(1,n):
    gcdi = gcd(a0, a[i])
    if gcdi < mingcd:
        mingcd = gcdi
        min0 = i
 
a1 = a[-1]
mingcd1 = a1
min1 = n-1
for i in range(n-1):
    gcdi = gcd(a1, a[i])
    if gcdi < mingcd1:
        mingcd1 = gcdi
        min1 = i

nend = n-1
if mingcd < mingcd1:
    a.pop(min0)
elif mingcd > mingcd1:
    a.pop(min1)
elif min0 == min1:
    a.pop(min0)
else:
    nend = n


a0 = a[0]
maxgcd = a0
for i in range(1,nend):
    gcdi = gcd(a0,a[i])
    if gcdi < maxgcd:
        maxgcd = gcdi
print(maxgcd)

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)

s_idx = 0
max_element = 1

for i in range(N):
    element = gcd(A[+i], A[(i + 1) % N])

    if N == 2:
        print(max(A))
        exit()
    else:
        for i in range(2,N-1):
            element=gcd(element,A[(i + 1) % N])
        
        if element > max_element:
            max_element = element
print(max_element)
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==1:
    print(10**9)
elif N==2:
    max(a)
else:
    print(best[N-1])

Submission status: Wrong Answer

Solution code:
import numpy as np

def gcd(a, b):
    maxV = max(a, b)
    minV = min(a, b)
    if minV == 0:
        return maxV
    else:
        return gcd(minV, maxV%minV)

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

maxg = 0
if N == 2:
    print(max(Alist))
else:
    gcalc = Alist[0]
    for i in range(0, N):
        tmp = np.array(Alist)
        g = 0
        if i != N - 1:
            tmp[i] = tmp[i + 1]
        else:
            tmp[i] = tmp[i - 1]
        if i == 0:
            for j in range(1, N):
                if j == 1:
                    g = gcd(tmp[0], tmp[1])
            else:
                g = gcd(g, tmp[j])
        else:
            for j in range(i, N):
                if j == i:
                    g = gcd(gcalc, tmp[j])
                    gcalc = g
                else:
                    g = gcd(g, tmp[j])
        if maxg < g:
            maxg = g
    print(maxg)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input()) 
alist = list(map(int, input().split()))

from functools import reduce

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

def gcd(*numbers):
  return reduce(gcd2, numbers)

max_gcd = 10**9
next_max_gcd = 10**9 -1
ansList = []
if len(alist) == 2:
  ans = max(alist)
else:
  for i, v in enumerate(alist):
    if i == len(alist) - 2:
      ansList.append(gcd2(alist[i], alist[i+1]))
    elif i < len(alist) - 2:
      a1 = gcd2(alist[i], alist[i+1])
      a2 = gcd2(alist[i], alist[i+2])
      ansList.append(max(a1,a2))
#      print(gcd2(alist[i], alist[i+1]))
#      if max_gcd > res_gcd:
#        max_gcd = next_max_gcd
#        next_max_gcd = res_gcd 
  sortList = sorted(ansList)
  ans = sortList[1]      
      
#print(res_gcd)  

# print(gcd(*alist))
# 9

print("{}".format(ans))

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):
    tmp_integers = copy.copy(integers)
    for x in change_to:
        tmp_integers[i] = x
        gcds.append(reduce(fractions.gcd, tmp_integers))
print(max(gcds))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    while (y != 0):
        x, y = y, x%y
    return (x)

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

result = 1
a[0] = a[1]

for i in range(1):
    for j in range(i+1,n):
        if(a[i]>result and (j > 1)):
            a[i]=result
        if(a[i] >= a[j]):
            result = gcd(a[i], a[j])
        elif(a[i] < a[j]):
           result = gcd(a[j], a[i])
        if (result == 1):
            break

Submission status: Wrong Answer

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

rest=0
max_a = 0

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

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            rest = gcd(aaa[i],aaa[j])
            max_a = max(max_a,rest)
        
print(max_a)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  for i in range(n-1):b.append(gcd(a[i],a[i+1]))
  b.append(gcd(a[0],a[-1]))
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  on,im=a[-1],a[-1]
  for i in range(1,n):
    s=gcd(on,a[n-i-1])
    if s!=on:
      on=max(s,im)
      im=gcd(s,im)
  on=max(no,on)
  no,mi=a[-1],a[-1]
  for i in range(n-1):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(max(no,on,sorted(b)[2]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
onceFlag=0
finalValue = 1
finalIndex = None
ans = 1
maxK =[]
lo = min(A)
for i in range(lo):
    i=i+1
    #print(i)
    onceFlag=0
    Value =1
    Index = 0
    for j in range(N):
    #割り切れるか判定
        if A[j] % i == 0:
            #print('割り切れる')
            1
        else:
            #print('割り切れない')
            onceFlag = onceFlag+1
            Value = A[j]
            Index = j
    #2回以上割り切れなかったら候補外として抜ける
        if onceFlag > 1:
            break
    #もし全部やり終えて1回で割り切れたら
        if j == N-1 and onceFlag == 1:
            finalValue = Value
            finalIndex = Index
            #print('新たに更新:'+str(Value)+'を'+str(i)+'に返納したらうまくいくよ')
            ans=i
    #もし全部やり終えて0回で割り切れたら->変更する必要なし
        elif j == N-1 and onceFlag == 0:
            finalValue = Value
#全てを終えて。。。
if finalIndex == None:
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
import math
import copy
n = int(input())
ans = 1
lists = list(map(int,input().split()))
if len(lists)==2:
    ans = max(lists)
else:
    k = max(lists)

    for i in range(1,int(math.sqrt(k)+1)):
        flag = False
        for j in range(len(lists)):
            if (lists[j]%i==0):
                flag = True
                lists[j] = lists[j]/i
    
        if not flag:
            continue
        else:
        
            ans *= i

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
  
N= int(input())
A = list(set(list(map(int, input().split()))))
gcd = []
 
for i in range(len(A)):
  a = A[i]
  A[i] = 0
  gcd.append(reduce(fractions.gcd, A))
  A[i] = a
print(max(gcd))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    a,b=sorted([a,b])
    while b%a!=0:
        a,b=b%a,a
    return a
n=int(input())
a=list(map(int, input().split()))
if(n==2):
    print(max(a))
    quit()
ans=0
for i in range(n):
    tmp=a[i-1]
    for j in range(n):
        if(j==1):
            continue
        tmp=gcd(tmp,a[j])
    ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

n=int(input())
A=list(map(int, input().split()))
#a=1
init=1
#maxa=99999999999999999999999999
#maxa=A[1]
B=[]
for i in A:
    if init==1:
        a=i
        init=0
        B.append(a)
    else:
        a=gcd(a,i)
        B.append(a)
#print(B)
#removenum=min(enumerate(B), key=lambda x: x[1])[0]
value=99999999999999999999999999999
for num,i in enumerate(B):
    if i<value:
        removenum=num
        value=i

#print(removenum)

init=1

#両はし
for num,i in enumerate(A):
    if num==removenum:
        continue
    if init==1:
        a=i
        init=0
    else:
        a=gcd(a,i)
#print(a)

init=1
for num,i in enumerate(A):
    if num==0:
        continue
    if init==1:
        b=i
        init=0
    else:
        b=gcd(b,i)

init=1
for num,i in enumerate(A):
    if num==len(A)-1:
        continue
    if init==1:
        c=i
        init=0
    else:
        c=gcd(c,i)

print(max(a,b,c))

Submission status: Wrong Answer

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

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(2, len(li)):
            temp=gcd(temp, li[i])
    return temp


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

t=a[0]
t2=a[1]
out=0
f=1
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    #print(t, a[i],out, min)
"""
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t2, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    print(t2, a[i],out, min)


print(out)
"""

"""
  if not (a[i]%t==0 or t %a[i]==0):
    if f:
      out=i
      f=0
    elif not f:
      out=0
"""
if not len(a)==2:
  temp=a[0:out]
  temp.extend(a[out+1:])
  #print(temp)
  itemp=ngcd(temp)
  itemp2=ngcd(a[1:])
  #print(itemp, itemp2)
  print(max(itemp, itemp2))
else:
  print(max(a[0], a[1]))


"""
max=0
for i in range(len(a)):
    temp=a[0:i]
    temp.extend(a[i+1:])
    itemp=ngcd(temp)
    if max < itemp:
        max=itemp

print(max)
"""