Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

3
7 6 8

Sample Output 1

2

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

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    ac = collections.Counter(LI())
    a = []
    aa = []
    for k,v in ac.items():
        if v > 1:
            aa.append(k)
        else:
            a.append(k)

    tr = -1
    if len(aa) > 0:
        tr = aa[0]
        for k in aa[1:]:
            tr = fractions.gcd(k,tr)

    l = len(a)
    if l < 1:
        return tr
    if l < 3:
        r = 0
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

    m = max(a)
    lm = m
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    t = c*(k**i)
                    r.append(t)
        for k in r:
            p[k] += 1



    if tr == -1:
        r = 1
        for k,v in p.items():
            if v >= l-1 and r < k:
                r = k
        return r

    r = 1
    for k,v in p.items():
        kk = fractions.gcd(tr,k)
        if v >= l-1 and r < kk:
            r = kk

    return r


print(main())

Submission status: Wrong Answer

Solution code:
import math
N =int(input())
a = input().split()
b=0
num=[]
test=[]
res=[]
for i in range(N):
  num.append(int(a[i]))
#a,bの最大公約数を求める
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y!=0:
      z = x%y
      x = y
      y = z
    else:
      return z
for j in range(N):
  test=num[:]
  if len(test) > 2:
    del test[j]
  else:
    res=[max(test)]
    break
  for i in range(N-1):
	  b = gcd(test[0],test[1])
	  b = gcd(b,test[i])
  res.append(b)

print(max(res))

Submission status: Wrong Answer

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

import fractions
from functools import reduce

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


ans=0
GCD_target=gcd_list(A)
#print("GCD_target = {}".format(GCD_target))

for i in range(N):
   copied_A = A[:]
   copied_A.pop(i)
   GCD_current=gcd_list(copied_A)
   #print(GCD_current)
   ans=max(ans,GCD_current)

print(ans)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int,input().split()))
a.append(0)
a.append(0)
a.sort(reverse=True)
result = make_divisors(a[0] - a[2])

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
n = int(input())
v_list = list(map(int, input().split()))
v_set = set(v_list)
if len(v_set) < 3:
    print(max(v_set))
else:
    v_list.sort()
    d_list = []
    check = v_list[0]
    for i in range(1, int(check/2)):
        if check % i == 0:
            d_list.append(i)
            d_list.append(int(check/i))
    d_list.sort()
    ans = 1
    for d in d_list[1:]:
        flag = 0
        for v in v_list[1:]:
            if v%d > 0:
                flag += 1
        if flag < 2:
            ans = d
    if ans == 1:
        d_list = []
        check = v_list[1]
        for i in range(1, int(check/2)):
            if check % i == 0:
                d_list.append(i)
                d_list.append(int(check/i))
        d_list.sort()
        for d in d_list[2:]:
            flag = 0
            for v in v_list[1:]:
                if v%d > 0:
                    flag = 1
                    break
            if flag == 0:
                ans = d
    print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
input()
a=list(set(map(int,input().split())))
n=len(a)
if n == 1:
    print(a[0])
elif n == 2:
    print(max(a[0], a[1]))
else:
    print(max(reduce(gcd, (a[i] for i in range(n) if i != j)) for j in range(n)))

Submission status: Wrong Answer

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

import fractions

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            G.append(fractions.gcd(A[i], A[j]))
            

print(max(G))

Submission status: Wrong Answer

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

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

divisors = make_divisors(A[-1])
for d in divisors:
  NG = 0
  for a in A:
    if a % d != 0:
      NG += 1
    if NG > 1:
      break
  if NG <= 1:
    print(d)
    break

Submission status: Wrong Answer

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

N = input()
As =  list(map(int, input().split()))
ar = set(sorted(As))

if(len(ar) < 3):
  print(list(ar)[-1])
  quit()

As = sorted(list(set(As)))
r = []
r.append(gcd(As[0], As[-1]))
r.append(gcd(As[1], As[-1]))
r.append(gcd(As[0], As[-2]))
print(max(r))

Submission status: Wrong Answer

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

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

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

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

A.sort()
B=A+[A[0]]
min1,min2=float('inf'),float('inf')
min1_idx,min2_idx=0,1
for i in range(n):
    g=gcd(B[i],B[i+1])
    if g<min1:
        min2=min1
        min2_idx=min1_idx
        min1=g
        min1_idx=i
    elif g<min2:
        min2=g
        min2_idx=i
    #print(g,min1,min2)
    #print(i,min1_idx,min2_idx)
#print(min1_idx,min2_idx)
if abs(min1_idx-min2_idx)==1:
    idx=max(min1_idx,min2_idx)
else:
    idx=0
#print(idx)
del A[idx]
#print(A)
ans=gcd(A[0],A[1])
for i in range(2,n-2):
    ans=gcd(ans,A[2])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    if fractions.gcd(li[1], li[2]) not in kouho:
        kouho.append(fractions.gcd(li[1], li[2]))
    if fractions.gcd(li[2], li[0]) not in kouho:
        kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
Al = list(map(int, input().split()))
a = 0
b = 0

if N == 2:
  a = max(Al)
  print(a)
else:
  for i in range(0, N-1):
    for j in range(i+1, N):
      c = fractions.gcd(Al[i], Al[j])
      if c > b:
        b = fractions.gcd(Al[i], Al[j])
  a = b
  print(a)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
input()
a=list(set(map(int,input().split())))
n=len(a)
if n == 1:
    print(a[0])
elif n == 2:
    print(gcd(a[0], a[1]))
else:
    print(max(reduce(gcd, (a[i] for i in range(n) if i != j)) for j in range(n)))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    ac = collections.Counter(LI())
    a = []
    aa = []
    for k,v in ac.items():
        if v > 1:
            aa.append(k)
        else:
            a.append(k)
    tr = -1
    if len(aa) > 0:
        tr = aa[0]
        for k in aa[1:]:
            tr = fractions.gcd(k,tr)

    l = len(a)
    if l < 1:
        return tr
    if l < 3:
        r = 0
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

    m = max(a)
    lm = m
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    t = c*(k**i)
                    if t > lm:
                        break
                    r.append(t)
        for k in r:
            p[k] += 1



    if tr == -1:
        r = 1
        for k,v in p.items():
            if v >= l-1 and r < k:
                r = k
        return r

    r = 1
    for k,v in p.items():
        kk = fractions.gcd(tr,k)
        if v >= l-1 and r < kk:
            r = kk

    return r


print(main())

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
n_gcd = a[0]
point_a = 0
point_b = 0
for i in range(1, n):
    num = fractions.gcd(n_gcd, a[i])
    if num < n_gcd:
        point_a, point_b = i-1, i
        n_gcd = num
a_b = copy.copy(a)
a.pop(point_a)
a_b.pop(point_b)
n_gcd_a = a[0]
n_gcd_b = a_b[0]
if len(a) == 1:
    print(a[0])
    exit()
for i in range(1, n-1):
    n_gcd_a = fractions.gcd(n_gcd_a, a[i])
for i in range(1, n-1):
    n_gcd_b = fractions.gcd(n_gcd_b, a_b[i])
print(max(n_gcd_a, n_gcd_b))

Submission status: Wrong Answer

Solution code:
n = int(input())
alist = [int(i) for i in input().split()]


def calc_gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


prev = None
gcm_list = []
for a in alist:
    if prev is None:
        gcm_list.append(a)
        prev = a
        continue
    ret = calc_gcm(a, prev)
    gcm_list.append(ret)
    prev = ret


for boundary, gcm in enumerate(gcm_list):
    if gcm == gcm_list[-1]:
        break


gcm_1 = None
for i, a in enumerate(alist):
    if i == boundary - 1:
        continue
    if gcm_1 is None:
        gcm_1 = a
        continue
    gcm_1 = calc_gcm(a, gcm_1)


gcm_2 = None
for i, a in enumerate(alist):
    if i == boundary:
        continue
    if gcm_2 is None:
        gcm_2 = a
        continue
    gcm_2 = calc_gcm(a, gcm_2)


print(max(gcm_1, gcm_2))

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
ans = A[1]
for i in range(2, N):
	ans = fractions.gcd(ans, A[i])
G = [A[0]]
for j in range(1, N):
	G.append(fractions.gcd(A[0], A[j]))
k = G.index(min(G))
B = A[: k] + A[k + 1:]
g = B[0]
for l in range(1, N - 1):
	g = fractions.gcd(g, B[l])
print(max(ans, g))

Submission status: Wrong Answer

Solution code:
import copy
from functools import reduce

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

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

if __name__ == '__main__':
    N = int(input())
    A_list = list(map(int, input().split()))

    answer = 0

    for i in range(0, len(A_list)-1):
        A_list_copy = copy.deepcopy(A_list)
        A_list_copy.pop(i)

        gcd_number = gcd_list(A_list_copy)

        if answer < gcd_number:
            answer = gcd_number

    print(answer)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    ac = collections.Counter(LI())
    a = []
    aa = []
    for k,v in ac.items():
        if v > 1:
            aa.append(k)
        else:
            a.append(k)
    tr = -1
    if len(aa) > 0:
        tr = aa[0]
        for k in aa[1:]:
            tr = fractions.gcd(k,tr)

    l = len(a)
    if l < 1:
        return tr
    if l < 3:
        r = 0
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

    m = max(a)
    lm = m // (l-1)
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    t = c*(k**i)
                    if t > lm:
                        break
                    r.append(t)
        for k in r:
            p[k] += 1



    if tr == -1:
        r = 1
        for k,v in p.items():
            if v >= l-1 and r < k:
                r = k
        return r

    r = 1
    for k,v in p.items():
        kk = fractions.gcd(tr,k)
        if v >= l-1 and r < kk:
            r = kk

    return r


print(main())

Submission status: Wrong Answer

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

def gcd(a,b):
    num = []
    num.append(max(a,b))
    num.append(min(a,b))
    i = 0
    while True:
        num.append(num[i]%num[i+1])
        if num[i+2] == 0:
            break
        else: 
            i += 1
    return num[i+1]

def gcd_list(A):
    for i in range(len(A)-1):
        A[i+1] = gcd(A[i],A[i+1])
    return A[-1]

print(gcd_list(A))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
a.sort()
for i in range(1,int(a[n-1]**0.5)+1):
    if a[n-1]%i==0:
        d[i] += 1
        if i!=a[n-1]//i:
            d[a[n-1]//i] += 1
for i in range(n-1):
    for k,v in d.items():
        if a[i]%k==0:
            d[k] += 1
sd = sorted(d.items(),key=lambda x:x[0],reverse=True)
for k,v in sd:
    if v==n or v==n-1:
        print(k)
        break

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#import math
import fractions as math

N = int(input())
A = list(map(int, input().split()))
memo = {}
x = A[1]
for a in A[2:]:
    n = math.gcd(x, a)
    memo[(x, a)] = n
    x = n
max_gcd = x

for i in range(N):
    x = A[0]
    for j in range(N):
        if i == j:
            pass
        else:
            if (x, A[j]) in memo:
                x = memo[(x, A[j])]
            else:
                n = math.gcd(x, A[j])
                memo[(x, A[j])] = n
                x = n
        if x < max_gcd:
            break
        else:
            max_gcd = x
print(max_gcd)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        now = gcd(A[i], A[j])
        if now > ans :
            ans = now
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
for i in range(n):
    for j in range(i+1,n):
        x = fractions.gcd(a[i], a[j])
        if x == 1:
            continue
        else:
            if list(map(lambda s: s%x, a)).count(0) == n:
                print(x)
            elif list(map(lambda s: s%x, a)).count(0) == n-1:
                print(x)
            else:
                continue

Submission status: Wrong Answer

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

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

dd = {}
for i in range(N):
    if A[i] not in dd.keys():
        dd[A[i]]= 0
    dd[A[i]] += 1
if len(dd.keys()) == 2:
    for key in dd.keys():
        if dd[key] == N - 1:
            print(max(A))
            exit()

mina = min(A)
maxa = max(A)
import fractions
d = {}
for i in range(N):
    k = fractions.gcd(mina , A[i])
    if k not in d.keys():
        d[k] = 0
    d[k] += 1
mind = min(d.keys())

if d[mind] == 1:
    j = sorted(d.keys())
    print(j[1])
else:
    print(mind)

Submission status: Wrong Answer

Solution code:
def make_divisors(arg):
    divisors = set()
    for i in range(1, int(arg**0.5)+1):
        if arg % i == 0:
            divisors.add(i)
            if i != arg // i:
                divisors.add(arg//i)

    return divisors


n = int(input())
a = list(map(int, input().split()))
a.sort()
a0y = make_divisors(a[0])
a1y = make_divisors(a[1])
common = a0y & a1y
one = a0y ^ a1y
last = 0
for e in a[2:]:
    if e == last:
        continue
    tmp = make_divisors(e)
    common = tmp & common
    one = (one & tmp) | (common - tmp)
    last = e

print(max(common.union(one)))

Submission status: Wrong Answer

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


def blackbord(n,a):
    if n==2 and a[0]==a[1]:
        return a[0]
    else:
        return max(list(hcf(i,j) for i in a for j in list(filter(lambda b:b!=i,a))))
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

Submission status: Wrong Answer

Solution code:
import re
import sys
from fractions import gcd
from functools import reduce
from itertools import product

import numpy as np

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()
    A = np.asarray(A)
    ans = 1
    flag = True
    for i in range(A.max(), 2, -1):
        a = A % i
        c = np.count_nonzero(a)
        if c <= 1:
            ans = i
            flag = False
        if not flag:
            break
    return ans


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

Submission status: Wrong Answer

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

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

if n > 2:
    a = gcd(s[0],s[1])
    b = gcd(s[1],s[2])
    c = gcd(s[2],s[0])

    large = max(a,b,c)
    small = min(a,b,c)
    p = large
    q = []
    if n == 3:
        print(large)
    else:
        for i in range(n-3):
            p = gcd(p,s[i+3])
            q.append(gcd(small,s[i+3]))
        q.sort()
        print(max(p,q[1]))
else:
    print(max(s))

Submission status: Wrong Answer

Solution code:
#C
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
N=int(input())
A = [int(j) for j in input().split()]
A=list(set(A))
A.sort()
ans=0

for a in A:
    if len(A)!=1:
        tmp=A.copy()
        tmp.remove(a)
        ans =max(ans,gcd(max(tmp),sum(tmp)))
    else:
        ans=A[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    ac = collections.Counter(LI())
    a = []
    aa = []
    for k,v in ac.items():
        if v > 1:
            aa.append(k)
        else:
            a.append(k)
    tr = -1
    if len(aa) > 0:
        tr = aa[0]
        for k in aa[1:]:
            tr = fractions.gcd(k,tr)

    l = len(a)
    if l < 1:
        return tr
    if l < 3:
        r = 0
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

    m = max(a)
    lm = m // (l-1)
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    t = c*(k**i)
                    if t > lm:
                        break
                    r.append(t)
        for k in r:
            p[k] += 1



    if tr == -1:
        r = 1
        for k,v in p.items():
            if v >= l-1 and r < k:
                r = k
        return r

    r = 1
    for k,v in p.items():
        kk = fractions.gcd(tr)
        if v >= l-1 and r < kk:
            r = kk

    return r


print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
L=[]
A=list(map(int,input().split()))
f=min(A)
F=min(A)
for i in range(f):
 L=list(map(lambda n:n%F,A))
 if max(L) == 0:
  break
 F-=1
print(F)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

nA = list(sorted(A))

d = [nA[i+1] - nA[i] for i in range(N-1)]

index = -1
d_min = pow(10,10)

for i,d_i in enumerate(d):
    if d_i < d_min:
        index = i
        d_min = d_i

note = nA[index+1]

res = [a for a in A if a != note]
if res == []:
    print(A[0])
    exit()
ans = gcd_list(res)
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(p,q):
  while q!=0:
    p,q=q,p%q
  return p

n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt1=0
cnt2=0
cnt3=0

if n==2:
  print(a[-1])
else:
  b=a[0]
  c=gcd(a[0],a[2])
  d=a[1]
  for i in range(n-1):
    if gcd(b,a[i+1])==1 and cnt1==0:
      cnt1=1
      continue
    else:
      b=gcd(b,a[i+1])
      
  if n>=4:
    for i in range(n-3):
      if gcd(c,a[i+3])==1 and cnt2==0:
        cnt2=1
        continue
      else:
        c=gcd(c,a[i+3])
  for i in range(n-2):
    if gcd(d,a[i+2])==1 and cnt3==0:
      cnt3=1
      continue
    else:
      d=gcd(d,a[i+2])
  print(max(b,c,d))

Submission status: Wrong Answer

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

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

print(gcd(max(A), min(A)))

Submission status: Wrong Answer

Solution code:

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

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

if n == 2:
    print(max(a))
    exit()
"""
a = a[0:3]
"""
#print(a)
p1 = gcd(a[0],a[1])
p2 = gcd(a[1],a[2])
p3 = gcd(a[0],a[2])

p = [p1,p2,p3]
"""
for i in p:
    if min(p) == i:
"""
"""
f1 = 0
f2 = 0
f3 = 0
res0 = []
res1 = []
res2 = []
res = []
for i in range(n):
    if a[i]%a[0]!= 0:
        f1 += 1
        res0.append(a[i])
        res.append(a[i])
    if a[i]%a[1]!= 0 and i>0:
        f2 += 1
        res1.append(a[i])
        res.append(a[i])
    if a[i]%a[2]!= 0 and i>1:
        f3 += 1
        res3.append(a[i])
        res.append(a[i])
    
    if sum(f1,f2,f3) > 1:
        print(1)
        break

    if sum(f1,f2,f3):
        res = res[i]
        break
        """
f = 0
tmp = a[0]
res1,res2,res3 = p1,p2,p3
for i in range(n):
    if gcd(tmp,a[i])==1:
        f += 1
    else:
        tmp = gcd(tmp,a[i])

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

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

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 l in range(N):
    c = a_list[l]
    if l != N-1:
        a_list[l] = a_list[l+1]
    else:
        a_list[l] = a_list[l-1]
    for i in range(N-1):
        b = gcd(a_list[i], a_list[i+1])
        ans.append(b)
    a_list[l] = c
if N > 2:
    ans.sort()
    print(ans[2])
else:
    print(max(a_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
def u(a, b):
    if b == 0:
        return a
    return u(b, a % b)

if len(A) <= 2:
    res = A[0]
else:
    res = 0
    for i in range(len(A)):
        tmp = list(A)
        tmp.pop(i)
        for k in range(len(tmp)-1):
            tmp[k+1] = u(tmp[k], tmp[k+1])
        res = max(res, tmp[len(tmp)-1])
print(res)