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 sys
import math
from collections import Counter
import itertools
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

N = INT()
A = MAP()
B = [tuple(prime_factor(a)) for a in A]

nums = []
for b in B:
	c=Counter(b)
	nums.extend(c.keys())
nums = (list(set(nums)))
nums.sort(reverse=True)

numnum = []
for num in nums:
	tmp = [0]*N
	for ix,b in enumerate(B):
		tmp[ix] = b.count(num)
	numnum.append(tmp)

#print(nums,numnum)

hosei = 1
ans = 1
for idx,num in enumerate(nums):
	if min(numnum[idx])==0:
		if hosei and numnum[idx].count(0)==1:
			#print(numnum[idx])
			ans *= num*1
			hosei -= 1
		else: continue
	else:
		ans *= num ** min(numnum[idx])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=sorted(set(list(map(int,input().split()))))
if len(a)==1:
  print(a[0])
  sys.exit()
i=a[1]
while i > 0:
  flg=0
  for j in a:
    if j%i!=0:
      flg+=1
      if flg>1:
        break
  if flg<=1:
    print(i)
    break
  else:
    i-=1

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
list_ = list(map(int, input().strip().split()))

gcd_from_left = [list_[0]]
gcd_from_right = [list_[-1]]
for i in range(n - 1):
    gcd_from_left.append(gcd(gcd_from_left[i], list_[i + 1]))
    gcd_from_right.append(gcd(gcd_from_right[i], list_[-(i + 1)]))

print(max(gcd(gcd_from_left[i], gcd_from_right[-i]) for i in range(n)))

Submission status: Wrong Answer

Solution code:
N = int(input())
import fractions

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

gcd_start = [0]
gcd_end = [0]

ans = a[0]
gcd_start.append(ans)
for i in range(1, N):
    ans = fractions.gcd(ans, a[i])
    gcd_start.append(ans)

ans = a[-1]
gcd_end.append(ans)
for i in range(N-1, 0, -1):
    ans = fractions.gcd(ans, a[i])
    gcd_end.append(ans)

ans_max = 0
for i in range(N):
    # print(gcd_end[-i-2], gcd_start[i])
    ans = fractions.gcd(gcd_end[-i-1], gcd_start[i])
    ans_max = max(ans, ans_max)

print(ans_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
flag = True
one_chance = True
ans = 1
while flag == True:
  flag = False
  for i in range(2, int(max(A) ** 0.5) + 2):
    for index, a in enumerate(A):
#      print(i, a, a % i)
      if a % i != 0:
        if one_chance == True:
          if index == n-1:
            A[index] = A[n-2]
          else:
            A[index] = A[index + 1]
          one_chance = False
        else:
          break
    else:
      for j in range(n):
        A[j] = A[j] // i
      ans *= i
      flag = True
#      print(i, A, flag)
  else:
    min_A = min(A)
    if min_A != 1:
      for j in range(n):
        if A[j] % min_A != 0:
          break
      else:
        for j in range(n):
          A[j] //= min_A
        ans *= min_A
        flag = True
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
flag = True
one_chance = True
ans = 1
while flag == True:
  flag = False
  for i in range(2, int(min(A) ** 0.5) + 2):
    for index, a in enumerate(A):
#      print(i, a, a % i)
      if a % i != 0:
        if one_chance == True:
          if index == n-1:
            A[index] = A[n-2]
          else:
            A[index] = A[index + 1]
          one_chance = False
        else:
          break
    else:
      for j in range(n):
        A[j] = A[j] // i
      ans *= i
      flag = True
#      print(i, A, flag)
  else:
    min_A = min(A)
    for j in range(n):
      if A[j] % min_A != 0:
        break
    else:
      for j in range(n):
        A[j] //= min_A
      ans *= min_A
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
if n == 2:
    print(max(a))
    exit()
x = [a[0], gcd(a[0], a[1])]
for i in range(n - 3):
    x.append(gcd(x[i], a[i + 2]))
ans = x[-1]
y = a[-1]
for i in range(1, n - 1):
    z = gcd(y, a[-i])
    ans = max(ans, gcd(x[-i - 1], z))
    y = z
print(max(ans, gcd(y, a[-n + 1])))

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)
ans=0
n=int(input())
a=list(map(int,input().split()))
if n==2:
  print(max(a))
  exit()
else:
  a.sort()
  x=gcd(a[0],a[1])
  y=gcd(a[0],a[2])
  z=gcd(a[1],a[2])
  if x==y:
    ans=x
  elif y==z:
    ans=y
  else:
    ans=z
  print(ans)

Submission status: Wrong Answer

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

n=int(input())
a=list(map(int,input().split()))
if n==2:
  print(max(a))
  exit()
else:
  a.sort()
  x=gcd(a[0],a[1])
  y=gcd(a[0],a[2])
  z=gcd(a[1],a[2])
  print(max(x,y,z))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

L = [0]
R = []
gcd_l = a[0]
gcd_r = a[-1]
for i in range(n):
    gcd_l = gcd(a[i],gcd_l)
    L.append(gcd_l)
    gcd_r = gcd(a[n-i-1],gcd_r)
    R.append(gcd_r)
R.append(0)
#print(*L)
#print(*R)
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=0
import fractions
L=[0]*n
R=[0]*(n+1)
for i in range(1,n):
  j=n-i-1
  L[i]=fractions.gcd(L[i-1],A[i])
  R[j]=fractions.gcd(R[j+1],A[i])

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

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
if N==2:
    x = max(A)
else:
    ind = 0
    a = A[1]
    for i in range(N):
        if i==ind:continue
        a1 = A[i]
        a = gcd(a,a1)
    x = a
    ind = 1
    a = A[0]
    for i in range(N):
        if i==ind:continue
        a1 = A[i]
        a = gcd(a,a1)
    x = max(x,a)
    a = gcd(A[0],A[1])
    cmin = a
    ind = 0
    for i in range(2,N):
        a1 = A[i]
        a = gcd(a,a1)
        if a<cmin:
            ind = i
            cmin = a
    if ind>0:
        a = gcd(A[0],A[1])
        for i in range(2,N):
            if i==ind:continue
            a1 = A[i]
            a = gcd(a,a1)
        x = max(x,a)
print(x)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
if N==2:
    x = max(A)
else:
    a = gcd(A[0],A[1])
    cmin = a
    ind = 1
    for i in range(2,N):
        b = A[i]
        a = gcd(a,b)
        if a<cmin:
            ind = i
            cmin = a
    a = A[(ind+1)%N]
    cmin = 10**9
    for i in range(N):
        if i==ind:continue
        b = A[i]
        a = gcd(a,b)
        cmin = min(cmin,a)
    a = A[1]
    dmin = 10**9
    for i in range(2,N):
        b = A[i]
        a = gcd(a,b)
        dmin = min(dmin,a)
    x = max(cmin,dmin)
print(x)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def p_c():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    *a, = map(int, input().split())
    ans = 0
    for i in range(n):
        tmp = a[i]
        a[i] = 0
        g = a[0]
        for j in range(1, n):
            g = gcd(g, a[j])
        a[i] = tmp
        if ans > g:
            ans = g
    print(ans)
    
p_c()

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
if n ==2:
    print(max(li))
else:
    li.sort()
    if li[0] == li[-1]:
        print(li[0])
        quit()
    a = li.pop(0)
    ans = 0
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    for i in range(1,n-1):
        temp = gcd(li[i],li[0])
        li[0] = temp
    ans = temp
    li.insert(0,a)
    li.pop(1)
    for i in range(1,n-1):
        temp = gcd(li[i],li[0])
        li[0] = temp
    print(max(temp,ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
if n ==2:
    print(max(li))
else:
    li.sort()
    a = li.pop(0)
    ans = 0
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    for i in range(1,n-1):
        temp = gcd(li[i],li[0])
        li[0] = temp
    ans = temp
    li.insert(0,a)
    li.pop(1)
    for i in range(1,n-1):
        temp = gcd(li[i],li[0])
        li[0] = temp
    print(max(temp,ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
if n ==2:
    print(max(li))
else:
    li.sort()
    a = li.pop(0)
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    ans = li[0]
    for i in range(1, n-1):
        ans = gcd(ans, li[i])
    li.insert(0,a)
    li.pop(1)
    for i in range(1, n-1):
        ans = gcd(ans, li[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
if n ==2:
    print(max(li))
else:
    li.sort()
    a = li.pop(0)
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    ans = li[0]
    for i in range(1, n-1):
        ans = gcd(ans, li[i])
    li.insert(0,a)
    li.pop(1)
    ans1 = li[0]
    for i in range(1, n-1):
        ans1 = gcd(ans1, li[i])
    print(max(ans,ans1))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
ans = 0
if n ==2:
    print(max(li))
else:
    li.sort()
    a = li.pop(0)
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    for i in range(1, n-1):
        ans = gcd(ans, li[i])
    li.insert(0,a)
    li.pop(1)
    ans = li[0]
    for i in range(1, n-1):
        ans = gcd(ans, li[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
ans = 0
if n ==2:
    print(max(li))
else:
    li.sort()
    a = li.pop(0)
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    ans = li[0]
    for i in range(1, n-1):
        ans = gcd(ans, li[i])

    li.insert(0,a)
    li.pop(1)
    for i in range(1, n-1):
        ans = gcd(ans, li[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
if n ==2:
    print(max(li))
else:
    li.sort()
    a = li.pop(0)
    ans = 0
    def gcd(x, y):
        while y > 0:
            x, y = y, x%y
        return x
    for i in range(1,n-1):
        temp = gcd(li[i],li[0])
        if temp > ans :
            ans = temp
    li.insert(0,a)
    li.pop(1)
    for i in range(1,n-1):
        temp = gcd(li[i],li[0])
        if temp > ans :
            ans = temp
    print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import fractions as f


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
b = copy.deepcopy(a)
ans = 1
min_a = min(a)

if (2 <= b.count(min_a)):
    a.append(min_a)

for e in b:
    if (len(a) == 1):
        ans = a[0]
    elif (len(a) == 2):
        ans = max(a[0], a[1])
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = f.gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import*

class MAX_SEGMENTTREE:
    def __init__(self,lis):
        length=len(lis)
        self.n=2**length.bit_length()
        self.node=[0]*(2*self.n-1)
        
        for i in range(length):
            self.node[i+self.n-1]=lis[i]
        for i in range(self.n-2,-1,-1):
            if self.node[2*i+1]<self.node[2*i+2]:
                self.node[i]=self.node[2*i+2]
            else:
                self.node[i]=self.node[2*i+1]

    def update(self,point,value):
        point+=self.n-1
        self.node[point]=value
        while point>0:
            point=(point-1)//2
            self.node[point]=gcd(self.node[2*point+2],self.node[2*point+1])
    
    def getmax(self,a,b):
        l,r = a+self.n,b+self.n
        ret = 0
        while l<r:
            if r&1:
                r-=1
                ret=gcd(self.node[r-1],ret)
            if l&1:
                ret=gcd(self.node[l-1],ret)
                l+=1
            l>>=1
            r>>=1
        return ret
        
n,*a=map(int,open(0).read().split())
m=MAX_SEGMENTTREE(a)

ans=1
for k,v in enumerate(a):
    m.update(k,0)
#    print(m.node)
    ans=max(ans,m.getmax(-1,n))
    m.update(k,v)
    
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import*

class MAX_SEGMENTTREE:
    def __init__(self,lis):
        length=len(lis)
        self.n=2**length.bit_length()
        self.node=[0]*(2*self.n-1)
        
        for i in range(length):
            self.node[i+self.n-1]=lis[i]
        for i in range(self.n-2,-1,-1):
            self.node[i]=gcd(self.node[2*i+1],self.node[2*i+2])

    def getmax(self,a,b):
        l,r = a+self.n,b+self.n
        ret = 0
        while l<r:
            if r&1:
                r-=1
                ret=gcd(self.node[l-1],self.node[r-1])
            if l&1:
                ret=gcd(self.node[l-1],self.node[r-1])
                l+=1
            l>>=1
            r>>=1
        return ret


n,*a=map(int,open(0).read().split())
segt=MAX_SEGMENTTREE(a)
#print(segt.node)
ans=-float("inf")
for i in range(n):
    g=segt.getmax(0,i)
    c=segt.getmax(i+1,n)
    if ans<gcd(g,c):
        ans=gcd(g,c)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import fractions as f


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
b = copy.deepcopy(a)
ans = 0

for e in b:
    if (len(a) == 1):
        ans = a[0]
    elif (len(a) == 2):
        ans = max(a[0], a[1])
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = f.gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import fractions as f


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
b = copy.deepcopy(a)
ans = 1

for e in b:
    if (len(a) == 1):
        ans = a[0]
    elif (len(a) == 2):
        ans = max(a[0], a[1])
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = f.gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy


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


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
b = copy.deepcopy(a)
ans = 0

for e in b:
    if (len(a) == 1):
        ans = a[0]
    elif (len(a) == 2):
        ans = max(a[0], a[1])
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy


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


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
b = copy.deepcopy(a)
ans = 0

for e in b:
    if (len(a) <= 2):
        ans = a[0]
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy


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


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
b = copy.copy(a)
ans = 0

for e in b:
    if (len(a) <= 2):
        ans = a[0]
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

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


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

for e in a:
    if (len(a) <= 2):
        ans = a[0]
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

n = int(input())
A = list(map(int, input().split()))
g = s_gcd(A)
B = [ i//g for i in A ]
s = set()
c = 0
b = B[0]
for i in range(1, n):
  if gcd(b, B[i]) == 1:
    s = i
    c += 1
    
if c == n-1:
  print(g * s_gcd(B[1:]))
elif c == 1:
  B.pop(s)
  print(g * s_gcd(B))
else:
  print(g)

Submission status: Wrong Answer

Solution code:
import functools
import copy

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

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

def gcd(nums): 
    return functools.reduce(euclid, nums)

A.append(A[-1])

max = gcd(A[1:])
for i in range(1, N):
    g1 = gcd(A[:i])
    g2 = gcd(A[i+1:])
    g = euclid(g1, g2)

    if g > max:
        max = g

print(max)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

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

GCD = 0

for i in range(0,len(A)):
  current = A[i]
  A[i] = A[i - 1]
  div = reduce(gcd,A)
  if div > GCD:
    GCD = div
  A[i] = current
  
print(GCD)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

N=int(input())
A=list(map(int,input().split()))
org_A=A[:]

temp=10**10
index=0
for i in range(N-1):
    A[i+1]=euclid(A[i],A[i+1])
    #print(A)
    if A[i+1]<temp:
        temp=A[i]
        index=i
#print(A,index)

X=org_A[:]
X.pop(index)
#print(X)
for i in range(N-2):
    X[i+1]=euclid(X[i],X[i+1])

Y=org_A[:]
Y.pop(index-1)
#print(Y)
for i in range(N-2):
    Y[i+1]=euclid(Y[i],Y[i+1])

if index==N-2:
    Z=org_A[:]
    Z.pop(-1)
    #print(Z)
    for i in range(N-2):
        Z[i+1]=euclid(Z[i],Z[i+1])
    print(max(min(X),min(Y),min(Z)))
    exit()

print(max(min(X),min(Y)))
#途中

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

N=int(input())
A=list(map(int,input().split()))
org_A=A[:]

temp=10**9
index=0
for i in range(N-1):
    A[i+1]=euclid(A[i],A[i+1])
    #print(A)
    if A[i+1]<temp:
        temp=A[i]
        index=i
#print(A,index)

X=org_A[:]
X.pop(index)
#print(X)
for i in range(N-2):
    X[i+1]=euclid(X[i],X[i+1])

Y=org_A[:]
Y.pop(index-1)
#print(Y)
for i in range(N-2):
    Y[i+1]=euclid(Y[i],Y[i+1])

if index==N-2:
    Z=org_A[:]
    Z.pop(-1)
    #print(Z)
    for i in range(N-2):
        Z[i+1]=euclid(Z[i],Z[i+1])
    print(max(min(X),min(Y),min(Z)))
    exit()

print(max(min(X),min(Y)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

N=int(input())
A=list(map(int,input().split()))
org_A=A[:]

temp=10**9
index=0
for i in range(N-1):
    A[i+1]=euclid(A[i],A[i+1])
    if A[i+1]<temp:
        index=i

X=org_A[:]
X.pop(index-1)
for i in range(N-2):
    X[i+1]=euclid(X[i],X[i+1])

Y=org_A[:]
Y.pop(index)
for i in range(N-2):
    Y[i+1]=euclid(Y[i],Y[i+1])

print(max(min(X),min(Y)))
#途中

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

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

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

log=10**9
place=0
for i in range(N-1):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)
    if log==temp:
        place=i

A.pop(place)
log=10**9
for i in range(N-2):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)

print(log)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

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

log=10**9
place=0
for i in range(N-1):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)
    if log==temp:
        place=i

A.pop(place)
log=A[0]
for i in range(N-2):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)

print(log)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

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

log=10**9
place=0
for i in range(N-1):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)
    if log==temp:
        place=i

A.pop(place)
log=10**9
for i in range(N-2):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)

print(log)

Submission status: Wrong Answer

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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(a[n-1])
r.append(a[n-1])
g=[]

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


for i in range(1,n):
  l.append(gcd(l[i],a[i-1]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))

Submission status: Wrong Answer

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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(a[n-1])
r.append(a[n-1])
g=[]

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


for i in range(1,n):
  l.append(gcd(l[i],a[i]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[i+1],r[n-i-1]))

print(max(g))

Submission status: Wrong Answer

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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(a[n-1])
r.append(a[n-1])
g=[]

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


for i in range(1,n):
  l.append(gcd(l[i],a[i]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[i+1],r[n-i]))

print(max(g))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
x=0
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
  
for i in range(0,n-1):
  for j in range(i+1,n):
    x=gcd(a[i],a[j])
    b.append(x)
    
print(max(b))

Submission status: Wrong Answer

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

def find_gcm(a,b):  #i>=j
    if a>=b:
        i=a
        j=b
    else:
        i=b
        j=a
    while j!=0:
        r=i%j
        i=j
        j=r
    return i
ans=[]
for i in range(n-1):
    k = a.pop(i)
    gcm = a[0]
    for j in range(1,n-2):
        gcm = find_gcm(gcm,a[j])
        if gcm == 1:
            break
    ans.append(gcm)
    a.insert(i,k)
print(max(ans))

Submission status: Wrong Answer

Solution code:

import sys

def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)
    
n = int(input())
a = list(map(int, input().split()))


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


tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])
print("used=", tmp_used, "unused=", tmp_unused)

for i in range(2,n):
  print(a[i])
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
  
  print("used=", tmp_used, "unused=", tmp_unused)
print(tmp_used)

Submission status: Wrong Answer

Solution code:

import sys

def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


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


tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])

for i in range(2,n):
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
      
print(tmp_used)

Submission status: Wrong Answer

Solution code:

import sys

def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


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

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<=10:
  maxgcd = ret(a)
else:
  tmp_unused = gcd3(a[:10])
  tmp_used = ret(a[:10])
  #print(a[:10])
  for i in range(10,n):
    #print(a[i])
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
    #print("tmp", tmp_unused, tmp_used)
  maxgcd=tmp_used
      
print(maxgcd)

Submission status: Wrong Answer

Solution code:

import sys

def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


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

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd = ret(a)
else:
  tmp_unused = gcd3(a[:10])
  tmp_used = ret(a[:10])
  #print(a[:10])
  for i in range(10,n):
    #print(a[i])
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)

Submission status: Wrong Answer

Solution code:

import sys
#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))


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

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd=ret(a)
else:
  tmp_unused = gcd3(a[:10])
  tmp_used = ret(a[:10])
  for i in range(10,n-1):
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)

Submission status: Wrong Answer

Solution code:

import sys
#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))

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

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd=ret(a)
else:
  tmp_unused = gcd3(a[:10])
  print(a[:10])
  tmp_used = ret(a[:10])
  for i in range(10,n-1):
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)

Submission status: Wrong Answer

Solution code:

import sys
#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
n = len(a)

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

def ret(a):
  maxgcd = 0
  for i in range(len(a)):
    nums = [a[j] for j in range(len(a)) if j!=i]
    tmp = gcd3(nums)
    if maxgcd<tmp:
      maxgcd=tmp
  return maxgcd
  

if len(a)<10:
  maxgcd=ret(a)
else:
  tmp_unused = gcd3(a[:10])
  print(a[:10])
  tmp_used = ret(a[:10])
  for i in range(10,n-1):
    tmp_unused = gcd(tmp_unused, a[i])
    tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  maxgcd=tmp_used
      
print(maxgcd)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
def gcd(n,m):
  r=1
  if n>=m:
    i=n
    j=m
  else:
    i=m
    j=n
  while(r>0):
    r=i%j
    i=j
    j=r
  return j
#def gcd_list(lis):
 # for i in range(len(lis)-1):
print(gcd(3,6))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

def gcd_list(numbers,n):
    temp = numbers[0]
    for i in range(n-1):
        temp = min(temp, gcd(numbers[i],numbers[i+1]))
    return temp

def main():
    n = int(input())
    A = list(map(int, input().split()))

    gcd_max = 1
    for i in range(n):
        if i == n-1:
            temp = A[i]
            A[i] = A[i-1]
            gcd_max = max(gcd_max, gcd_list(A,n))
            A[i] = temp
            break
        temp = A[i]
        A[i] = A[i+1]
        gcd_max = max(gcd_max, gcd_list(A,n))
        A[i] = temp
    print(gcd_max)


if __name__ == '__main__':
    main()