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
# gcd
import fractions
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
from functools import reduce


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


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


#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
old_gcd = gcd_list(A)
for i in range(N):
    A[i] = A[i] // old_gcd
i = N // 2
prev = 0
while i != prev:
    if gcd_list(A[i:N]) == 1:
        prev = i
        i = (i + N - 1) // 2
        continue
    else:
        i = (prev + i) // 2
        continue
A.pop(i)
print(old_gcd * gcd_list(A))
# print(A)
#
# num = N
# ans = []
# while num != 2:
#     ans = []
#     if num % 2 == 0:
#         num = -(-num // 2)
#         for i in range(num):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#     else:
#         num = -(-num // 2)
#         for i in range(num - 1):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#             ans.append(A[-1])
#     if ans.count(1) >= 2:
#         print(old_gcd)
#         break
# else:
#     print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
A_arr = list(map(int, input().split()))

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

gcd_list = []

if N == 2:
    print(max(A_arr))
    sys.exit()

for i in range(1, N):
    gcd_list.append(gcd(A_arr[0],A_arr[i]))

min_gcd = min(gcd_list)

for i in range(N-1):
    if gcd_list[i] == min_gcd:
        idx = i+1

gcd_list.remove(min_gcd)
gcd_list2 = []

if min_gcd in gcd_list:
    A_arr.pop(0)
    ans = A_arr[0]
    for i in range(1, N-1):
        ans = gcd(ans, A_arr[i])

else:
    A_arr.pop(idx)
    ans = A_arr[0]
    for i in range(1, N-1):
        ans = gcd(ans, A_arr[i])

print(ans)

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抜き
    for a in range(len(q) -1): 
        s = gcd(q[a],q[a+1])
    m.append(s)
m.sort()

print(m[-1])

Submission status: Wrong Answer

Solution code:
from sys import exit
def gcd(a,b):#greatest common divisor
    if (a<b):
        a,b = b,a
    while(b>0):
        a,b = b ,a%b
    return a
N = int(input())
A = [int(n) for n in input().split()]
gcds = {}
for i in range(1,N):
    g = gcd(A[0],A[i])
    if(g in gcds):
        gcds[g]+=1
    else:
        gcds[g]=1
for i in range(2,N):
    g = gcd(A[1],A[i])
    if(g in gcds):
        gcds[g]+=1
    else:
        gcds[g]=1
ans = sorted(list(gcds.keys()))
# print(gcds)
# print(ans)
tmpli = []
for i in gcds.keys():
    tmpli.append([i,gcds[i]])
tmpli = sorted(tmpli, key=lambda x:x[0])
# print(tmpli)
for g in tmpli:
    if(g[1] > N-1):
        print(g[0])
        exit()
if(len(tmpli) == 1):
    print(tmpli[0][0])
    exit()
print(tmpli[1][0])

# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()

Submission status: Wrong Answer

Solution code:
# coding=utf-8


def solve_gcd_from_list(number_list):
    if len(number_list) == 1:
        return number_list[0]

    if len(number_list) == 2:
        return solve_gcd(number_list[0], number_list[1])
    mid = len(number_list) // 2
    return solve_gcd(solve_gcd_from_list(number_list[:mid]), solve_gcd_from_list(number_list[mid:]))


def solve_gcd(number1, number2):
    if number1 == number2:
        return number1

    if number1 < number2:
        number1, number2 = number2, number1

    if number1 % number2 == 0:
        return number2

    return solve_gcd(number2, number1 % number2)


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

    A.sort()
    num = A.pop(0)
    gcd_list = [solve_gcd(num, n) for n in A]

    if all([gcd_list[0] == n for n in gcd_list]):
        num2 = gcd_list[0]
        rest_gcd = solve_gcd_from_list(A)
        print(max(num2, rest_gcd))

    else:
        gcd_list.sort()
        print(gcd_list[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)
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

l.sort()
ans=1

b=l[1]
bl=make_divisors(b)
for i in bl:
    check=True
    for j in range(n):
        if j%i!=0:
            check=False
            break
    if check:
        ans=max(ans,i)
        break
a=min(l)
al=make_divisors(a)
#print(al)
for i in al:
    cnt=0
    for j in range(n):
        if j%i!=0:
            cnt+=1
        if cnt>1:
            break
    if cnt==0 or cnt==1:
        ans=max(ans,i)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
min_a=min(a)
"""
def primes(max_number):

    指定値未満の素数を取得するジェネレータ
    :param max_number: 最大値
    :return: 素数ジェネレータ

    if max_number <= 2:
        raise StopIteration
    yield 2
    is_prime = [1] * max_number
    square_root_of_max = max_number ** 0.5
    for number in range(3, max_number, 2):
        if is_prime[number] is 0:
            continue
        yield number
        if number <= square_root_of_max:
            for multiple in range(number * 2, max_number, number):
                is_prime[multiple] = 0
"""
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

a.sort()
if n==2:
    print(max(a))
else:
    kouho_1=gcd(a[0], a[1])
    kouho_2=gcd(a[1], a[2])
    kouho_3=gcd(a[0], a[2])
    kouho=max(kouho_1, kouho_2, kouho_3)
    print(kouho)

Submission status: Wrong Answer

Solution code:

n = int(input())

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


from functools import lru_cache
import sys
if n == 2:
    print(max(a))
    sys.exit()


@lru_cache(maxsize=100000)
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def gcd_list(li):
    if len(li) == 1:
        return li[0]
    g = gcd(li[0], li[1])
    for i in range(2, len(li)):
        g = gcd(g, li[i])
    return g


def gcd_list_2(li):
    g = gcd(li[0], li[1])
    if g == 1:
        return max(gcd_list([li[0]] + li[2:]), gcd_list(li[1:]))
    for i in range(2, n):
        if gcd(g, li[i]) == 1:
            return gcd_list([g] + li[i + 1:])
        else:
            g = gcd(g, li[i])
    return g


def max_gcd(a):
    g = gcd_list(a)
    a = [a[i]//g for i in range(n)]
    m = gcd_list_2(a)
    print(g * m)


max_gcd(a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n == 2:
  gcdnum = max(numbers[0], numbers[1])
else:
  gcdnum = max(gcd(numbers[0], numbers[1]), gcd(numbers[0], numbers[2]), gcd(numbers[1], numbers[2]))
  for i in range(3, n):
    if gcd(gcdnum, numbers[i]) == 1:
      gcdnum = 1
      break
    else:
      gcdnum = gcd(gcdnum, numbers[i])
    
print(gcdnum)

Submission status: Wrong Answer

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

divs = []
def divisors(num):
  divisors = []
  # print(int(num**0.5))
  for i in range(1, int(num**0.5) + 1):
    if num % i == 0:
      divisors.append(i)
      if i != num // i:
          divisors.append(num//i)
  # print(divisors)
  return divisors

for a in A:
  divs.extend(divisors(a))

# print(set(divs))
# print(divs)
duplicate = sorted([x for x in set(divs) if divs.count(x) > 1])
print(duplicate[-1])

Submission status: Wrong Answer

Solution code:
from functools import reduce

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

def gcda(arr, left, right):
    return reduce((lambda a,b:gcd(a,b)), arr[left:right+1], gcd(arr[left], arr[right]))

n = int(input())
nums = [ int(s) for s in input().split(" ")]

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

allgcd = gcda(nums, 0, n-1)

found = 0
delete_kouho = -1
for i in range(1,n):
    if gcd(nums[0], nums[i]) == allgcd:
        found += 1
        delete_kouho = i

if found >= 2:
    print(gcda(nums, 1, n-1))
    exit()
elif delete_kouho == n-1 :
    print(gcda(nums, 0, n-2))
    exit()
else:
    print(gcd(gcda(nums, 0, delete_kouho-1), gcda(nums, delete_kouho+1, n-1)))

Submission status: Wrong Answer

Solution code:
import fractions


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    sortedA = sorted(A)
    minNum = sortedA[0]
    scdNum = sortedA[1]

    gcd_list = []
    for i in range(N):
        gcd_list.append(fractions.gcd(minNum, sortedA[i]))

    gcd_listScd = []
    for i in range(1, N):
        gcd_listScd.append(fractions.gcd(scdNum, sortedA[i]))

    gcd_list = sorted(gcd_list)
    gcd_listScd = sorted(gcd_listScd)
    print(max(gcd_list[1], gcd_listScd[0]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

        else:
            continue

print(max_gcd)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

A.sort()
count = []

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

list_A_0 = make_divisors(A[0])

#print(list_A_0)

for j in range(len(list_A_0)):
    count.append(0)
    for i in range(1,N):
        if A[i] % list_A_0[j]:
            pass
        else:
            count[j] += 1
dict_div = {}
for k in range(len(count)):
    dict_div[list_A_0[k]] = count[k]

#print(count)
#print(dict_div)

dict_div = dict(sorted(dict_div.items(), key=lambda x: -x[1]))
#print(dict_div)

#N-2 と N-1　回割れている要素のなかで一番大きいものを出力？
asm = []

for i,j in dict_div.items():
    if j == N-2 or j == N-1:
        asm.append(i)
        
def gcd(*numbers):
    return reduce(math.gcd, numbers)

if asm:
    print(max(asm))
else:
    print(gcd(A[1:]))

Submission status: Wrong Answer

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

def readInts():
  return [int(s) for s in input().split(" ")]

def gcd(m, n):
  if n == 0:
    return m
  return gcd(n, m % n)

def main():
  N = readInts()[0]
  A = readInts()

  rgcds = [1 for _ in range(N)]
  rgcds[N-1] = A[N-1]
  for i in range(N-2, 0, -1):
    rgcds[i] = gcd(A[i], rgcds[i+1])

  lgcds = [1 for _ in range(N)]
  lgcds[0] = A[0]
  for i in range(1, N):
    lgcds[i] = gcd(A[i], lgcds[i])

  m = 1
  for i in range(N):
    if i == 0:
      m = max(rgcds[i+1], m)
    if i == N-1:
      m = max(lgcds[i-1], m)
    else:
      m = max(gcd(lgcds[i-1], rgcds[i+1]), m)
  print(m)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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


n = int(input())  # ���l
a = list(map(int, input().split()))  # �������l�����X�g�Ɋi�[

li = []
for i in range(n - 1):
    li.append(gcd(a[i], a[i + 1]))

    if (n - 2) != i and n != 2:
        li.append(gcd(a[i], a[i + 2]))

li.sort()

if(n == 2):
    print(max(a[0], a[1]))
elif (n == 3):
    print(li[2])
else:
    print(li[3])

Submission status: Wrong Answer

Solution code:
N=int(input())

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


a=sorted(a)

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



l=1
r=10**9
a.sort()
ans=[a[0],a[1]]
k=-1
nexts=0
stock=0


ans=gcd(a[0],a[1])
for j in range(2,len(a)):
    s=gcd(ans,a[j])
    if(s<ans and stock==0):
        stock+=1
        nexts=s
    elif(s<ans and stock==1):
        if(s==nexts):
            stock-=1
            ans=s
        else:
            ans=max(s,nexts)
ans1=ans

ans=a[0]
for j in range(2,len(a)):
    ans=gcd(ans,a[j])
ans2=ans
ans=a[1]
for j in range(2,len(a)):
    ans=gcd(ans,a[j])

ans3=ans

    

print(max([ans1,ans2,ans3]))

Submission status: Wrong Answer

Solution code:
import fractions


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    sortedA = sorted(A)
    minNum = sortedA[0]
    scdNum = sortedA[1]

    gcd_list = []
    for i in range(N):
        gcd_list.append(fractions.gcd(minNum, sortedA[i]))

    gcd_listScd = []
    for i in range(1, N):
        gcd_listScd.append(fractions.gcd(scdNum, sortedA[i]))

    gcd_list = sorted(gcd_list)
    gcd_listScd = sorted(gcd_listScd)
    print(gcd_list)
    print(gcd_listScd)
    print(max(gcd_list[1], gcd_listScd[0]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#素数or 最も公約数の少ない数を、公約数が多いやつに書き換える
N = int(input())
A = list(map(int,input().split()))
big = 1
leastIndex = 0
sa = 0
for r in A:
    big *=r
def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
first = gcd(big,A[1])
for i in range(N-2):
    tmp =gcd(first, A[i+2])
    if first > tmp:
        if sa < first-tmp:
            sa = first-tmp
            leastIndex = i
    first = tmp
second  = gcd(A[0],big)
for m in range(N-2):
    second = gcd(second, A[m+2])
A[leastIndex] = big
third= gcd(A[0],A[1])
for m in range(N-2):
    third = gcd(third, A[m+2])
print(max(max(first,second),third))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import re
import math

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

r = {}

for j in a:
    for i in range(1, int(j**0.5)+1):
        if j % i == 0:
            if i in r.keys():
                r[i] += 1
            else:
                r[i] = 1
            if i != j // i:
                if j//i in r.keys():
                    r[j//i] += 1
                else:
                    r[j//i] = 1

r[1] = 0
m = max(r.values()) - 1
r_a = sorted([i[0] for i in r.items() if i[1] >= m], reverse=True)
print(r_a[0])

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)
        if tmp.index(tmp[i]) < i:
            continue
        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)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import copy

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
n = int(input())
A = list(int(i) for i in (input().split()))

red_list = list(set(A))

ans = 0
tmp = 0
reduce_num = 0
for i in range(len(red_list)):
  if(len(red_list) == 1):
    ans = red_list[0]
    break
  if( i != 0): red_list.append(reduce_num)
  reduce_num = red_list.pop(0)
  tmp = gcd_list(red_list)
  if(ans < tmp):
    ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
N = int(input())
Alist = list(map(int, input().split()))
def gcd(a,b):
    if a<b:
      a,b = b,a
    while b!=0:
        a,b = b, a%b
    return a
def gcd_list(numbers):
  return reduce(gcd, numbers)
print(max([gcd_list(Alist[:i]+Alist[i+1:])for i in range(N)]) if len(Alist)>2 else gcd_list(Alist))

Submission status: Wrong Answer

Solution code:
from fractions import gcd  # in math module python >= 3.5
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    b = list(set(a))
    if len(b) > 2:
        a = b
    for i in range(len(a)):
        excepted = [a[j] for j in range(len(a)) if j != i]
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))

    print(max(gcds))


main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
min_a=min(a)
"""
def primes(max_number):

    指定値未満の素数を取得するジェネレータ
    :param max_number: 最大値
    :return: 素数ジェネレータ

    if max_number <= 2:
        raise StopIteration
    yield 2
    is_prime = [1] * max_number
    square_root_of_max = max_number ** 0.5
    for number in range(3, max_number, 2):
        if is_prime[number] is 0:
            continue
        yield number
        if number <= square_root_of_max:
            for multiple in range(number * 2, max_number, number):
                is_prime[multiple] = 0
"""
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

a.sort()
if n==2:
    print(max(a))
else:
    kouho_1=gcd(a[0], a[1])
    kouho_2=gcd(a[1], a[2])
    if kouho_1>=kouho_2:
        kouho=kouho_1
    else:
        kouho=kouho_2

    print(kouho)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a
 
 
N = int(input())
A = [int(_) for _ in input().split()]
A = sorted(A)
GCD = []
 
if N == 2:
    print(max(A[0], A[1]))
else:
    for i in range(1, N):
        GCD.append(gcd(A[0], A[i]))
    
    GCD = sorted(GCD)
    
    ans = GCD[1]
    
    tmp = A[1]
    for i in range(2, N):
        tmp = gcd(tmp, A[i])
    
    if tmp > ans:
        ans = tmp
    
    print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce

#素因数分解
from collections import Counter

def factorint(N):
    table = []
    while(N > 1):
        for i in range(2,N+1):
            if N%i == 0:
                while N%i == 0:
                    N = N//i
                    table.append(i)
                break
    table_ = Counter(table)
    # print(table_)
    return table_

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

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

ans = 1
A.sort()
gcd1 = gcd(A)
for i in range(N):
    A[i] //= gcd1

ans *= gcd1
mix = 1
for i in range(N):
    mix *= A[i]

dic = factorint(mix)
fact_cnt = 0
potential = []
for key in dic.keys():
    if dic[key]==1:
        potential.append(key)
potential.sort()
gcd2 = 1
for i in range(len(potential)):
    if potential[i] in A:
        a = copy.deepcopy(A)
        a.remove(potential[i])
        gcd2 = max(gcd2,gcd(a))

ans *= gcd2

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions, sys
from functools import reduce

def gcd(numbers) :
    return reduce(fractions.gcd, numbers)
  
def ans(list,div = 1) :
  tmp = gcd(list)
  if tmp != 1 :
    for i in range(len(list)) :
      list[i] /= tmp
      div *= tmp
      
  return(list,tmp)

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

A, div = ans(A)
for i in range(N) :
  tmp = gcd(A[0:i] + A[i+1:N])
  if tmp != 1 :
    print(int(tmp * div))
    sys.exit()
print(div)

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

G = len([i for i in A if i % 2 == 0])
K = len([i for i in A if i % 2 == 1])
GG = [i for i in A if i % 2 == 0]
KK = [i for i in A if i % 2 == 1]
if abs(G - K) > 0 and G > 0 and K > 0:
  temp = A[:]
  temp.remove(max(KK))
  temp.append(max(GG))
  list.append(gcd_list(temp))

  temp = A[:]
  temp.remove(max(GG))
  temp.append(max(KK))
  list.append(gcd_list(temp))
else:
  temp = A[:]
  temp[N - 1 - 1] = temp[N - 1]
  list.append(gcd_list(temp))

#print(list)
print(max(list))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if N == 2:
    ans = max(A)

else:
    memo = {(0,0):1, (N,N):1}

    for i in range(1,N+1):

        if i == 1:
            memo[(0,1)] = A[0]
            memo[(N-1,N)] = A[-1]

        else:

            # gcd first i
            memo[(0,i)] = gcd(memo[(0,i-1)], A[i-1])

            # gcd last i
            memo[(N-i,N)] = gcd(memo[(N-i+1,N)], A[-i])

    ans = -1

    for i in range(1,N+1):

        curgcd = gcd(memo[(0,i-1)], memo[(i,N)])

        ans = max(ans, curgcd)

    gcd_all = gcd(A[0], memo[(1,N)])

    ans = max(ans, gcd_all)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

N = int(input())
A = [int(x) for x in input().split()]
cand = 0
mingcd = gcd_list(A)
if(N==2):
    print(max(A))
else:
    for i in range(N-1):
        if(mingcd==fractions.gcd(A[i],A[i+1])):
            if(i<N-2):
                if(mingcd==fractions.gcd(A[i],A[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                cand = i+1
    print(gcd_list(A[:cand]+A[cand+1:]))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
A_arr = list(map(int, input().split()))

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

gcd_list = []

if N == 2:
    print(max(A_arr))
    sys.exit()

for i in range(1, N):
    gcd_list.append(gcd(A_arr[0],A_arr[i]))

min_gcd = min(gcd_list)

for i in range(N-1):
    if gcd_list[i] == min_gcd:
        idx = i+1

gcd_list.remove(min_gcd)
gcd_list2 = []

if min_gcd in gcd_list:
    ans = 100000000000
    for i in range(2, N):
        ans = min(ans,gcd(A_arr[1],A_arr[i]))
else:
    A_arr.pop(idx)
    ans = A_arr[0]
    for i in range(1, N-1):
        ans = gcd(ans, A_arr[i])

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
A.sort()
ans = 1000000000
ansbuf = 0
index = 0
if len(A) >= 3:
    for lop in range(1,len(A)):
        buf = fractions.gcd(A[lop-1],A[lop])
        if ans > buf :
            index = lop
            ans = buf
    A[index] = A[0]
    ans = 1000000000
    for lop in range(1,len(A)):
        buf = fractions.gcd(A[lop-1],A[lop])
        if ans > buf :
            ans = buf  
    print(ans)
else:
    print(max(A))

Submission status: Wrong Answer

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

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

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

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

INF = 1<<29

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

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

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


N = int_raw()
As = ints_raw()


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


print(main())

Submission status: Wrong Answer

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




N = int(input())
A = [int(x) for x in input().split()]
a2 = list(A)
max = 0
mem = {}
for i,_ in enumerate(A):
    A.pop(i)
    res = A[0]
    for i in A[1:]:
        str12 = "{}.{}".format(i,res)
        str11 = "{}.{}".format(res,i)
        if str12 in mem.keys():
            res = mem[str12]
        elif str11 in mem.keys():
            res = mem[str11]
        else:
            res = gcd(res,i)
            mem[str12] = res
    max = res if res >= max else max
    A = list(a2)


print(max)

Submission status: Wrong Answer

Solution code:
from sys import stdin
#import math
import fractions
input=[]
for i in range(2):
    input.append(stdin.readline().rstrip().split())

N=int(input[0][0])
A=[]
for i in input[1]:
    A.append(int(i))

#print(N,A)

"""
x=0
for i in range(N):
    if i <= 1:
        x=math.gcd(A[0],A[1])
    else:
        x=math.gcd(x,A[i])
print(x)
"""
x=0
output=0
for i in range(N):
    copy_A=A.copy()
    copy_A.pop(i)
    if len(A)==2:
        output=fractions.gcd(A[0],A[1])
        break

    else:
        for i in range(N-1):
            if i <= 1:
                x=fractions.gcd(copy_A[0],copy_A[1])
            else:
                x=fractions.gcd(x,copy_A[i])
        if output<x:
            output=x

print(output)

Submission status: Wrong Answer

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

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

    divisors.sort()
    return divisors

adic = {}
#kouho = []
g = 0
for a1 in a:
    diva = make_divisors(a1)
    for diva1 in diva:
        if diva1 in adic.keys():
            adic[diva1] += 1
            #l = adic[diva1] >= N-1: 
            if adic[diva1] >= N-1:
                #kouho.append(diva1)
                g = max(g,diva1)
        else:
            adic[diva1] = 1
#print(adic)
#print(kouho,max(kouho))
print(g)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
from fractions import gcd
gcd_all=gcd(a[0],a[1])
gcd_eli=[a[0],a[1]]
for i in range(2,n):
    temp0=gcd(gcd_eli[0],a[2])
    temp1=gcd(gcd_eli[1],a[2])
    gcd_eli=sorted([temp0,temp1,gcd_all])[1:]
    gcd_all=gcd(gcd_all,a[2])
print(max(gcd_all,max(gcd_eli)))

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
A.sort()
ans = 1000000000
ansbuf = 0
index = 0
if len(A) >= 3:
    for lop in range(1,len(A)):
        buf = fractions.gcd(A[lop-1],A[lop])
        if ans > buf :
            index = lop
            ans = buf
    A[index] = A[0]
    ans = 1000000000
    for lop in range(1,len(A)):
        buf = fractions.gcd(A[lop-1],A[lop])
        if ans > buf :
            ans = buf  
else:
    print(max(A))
print(ans)

Submission status: Wrong Answer

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

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

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

if n > 100:
  n = 100

for i in range(n):
  b = copy.copy(a)
  b.pop(i)
  t = gcd(b)
  if ans < t:
    ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import fractions
import functools
import math


def number_of_divisors(x):
    res = 0
    for i in range(1, math.floor(math.sqrt(x)) + 1):
        d, m = divmod(x, i)
        if m == 0:
            res += 1 + int(d != i)
    return res


def gcds(xs):
    return functools.reduce(fractions.gcd, xs)


def solve(xs):
    m = min(xs, key=number_of_divisors)
    ys = xs[:]
    for i in range(len(ys)):
        if ys[i] == m:
            ys[i] = 0
            break
    return gcds(ys)


def main():
    _ = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(xs))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


n = int(input())
a_lst = list(map(int,input().split()))
a_lst.sort()
cnt = 0
ans = 1
temp_ans = 0
diff_1 = [1,0,0,0,-1]
diff_2 = [0,1,0,-1,0]

for i in range(0,len(diff_1)):
    d1,d2 = diff_1[i],diff_2[i]
    if (d1+d2) != 0:
        cnt += 1
    else:
        cnt = 0
    
    temp_ans = gcd(max(a_lst)+d1,min(a_lst)+d2)
    for a in a_lst[1:-1]:
        if cnt > 1:
            break
        if a%temp_ans != 0:
            cnt += 1
    if cnt <= 1:
        ans = max(ans,temp_ans)
print(ans)

Submission status: Wrong Answer

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

flag=False
for h in range(n):
    if a[h]%w[0]!=0 and flag==True:
       break
    if a[h]%w[0]!=0:
        flag=True
    if h==n-1:
        ans=w[0]
        end=True

y=1000000001
for i in range(n):
    y=min(y,a[i])
    



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


print(ans)