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
input=sys.stdin.readline

import math
def findFactors(n):
    now=n
    d={}
    cnt=0
    while now%2==0:
        now//=2
        cnt+=1
    if cnt>0:
        d[2]=cnt
    p=3
    while p<=math.sqrt(n):
        cnt=0
        while now%p==0:
            now//=p
            cnt+=1
        if cnt>0:
            d[p]=cnt
        if now==1:
            break
        p+=2
    if now>math.sqrt(n):
        d[now]=1
    return d

n=int(input())
A=list(map(int,input().split()))
D={} #素因数の個数のワースト1位と2位を記録する
F=findFactors(A[0])
for f in F:
    D[f]=[F[f],-1]

for i in range(n-1):
    F=findFactors(A[i+1])
    for d in D: #今までの素因数に対して
        if d in F: #現在の素因数にもあるとき
            k1=D[d][0]
            k2=D[d][1]
            now=F[d]
            if k2==-1:
                D[d][0]=min(now,k1)
                D[d][1]=max(now,k1)
            elif k1<=now<k2:
                D[d][1]=now
            elif k1>now:
                D[d][0]=now
                D[d][1]=k1
        else: #ないとき
            D[d][1]=D[d][0]
            D[d][0]=0
    if i==0:
        for f in F: #現在の素因数に対して
            if not f in D: #現在の素因数にないとき
                D[f]=[0,F[f]]

ans=1
for d in D:
    ans*=d**D[d][1]
print(ans)

Submission status: Wrong Answer

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

import math
def findFactors(n):
    now=n
    d={}
    cnt=0
    while now%2==0:
        now//=2
        cnt+=1
    if cnt>0:
        d[2]=cnt
    p=3
    while p<=math.sqrt(n):
        cnt=0
        while now%p==0:
            now//=p
            cnt+=1
        if cnt>0:
            d[p]=cnt
        if now==1:
            break
        p+=2
    if now>math.sqrt(n):
        d[now]=1
    return d

n=int(input())
A=list(map(int,input().split()))
D={} #素因数の個数のワースト1位と2位を記録する
F=findFactors(A[0])
for f in F:
    D[f]=[F[f],-1]


for i in range(n-1):
    F=findFactors(A[i+1])
    for d in D: #今までの素因数に対して
        if d in F: #現在の素因数にもあるとき
            k1=D[d][0]
            k2=D[d][1]
            now=F[d]
            if k2==-1:
                D[d][0]=min(now,k1)
                D[d][1]=max(now,k1)
            elif k1<=now<k2:
                D[d][1]=now
            elif k1>now:
                D[d][0]=now
                D[d][1]=k1
        else: #ないとき
            D[d][1]=D[d][0]
            D[d][0]=0
    for f in F: #現在の素因数に対して
        if not f in D: #現在の素因数にないとき
            D[f]=[0,F[f]]

ans=1
for d in D:
    ans*=d**D[d][1]
print(ans)

Submission status: Wrong Answer

Solution code:
#最大公約数、最小公倍数、階乗
import fractions
n = int(input())
a = list(map(int, input().split()))
def calcGCD(l,r):
    tmp = l
    ans = a[l]
    if l == r:
        return ans
    while tmp+1 != r:
        ans = fractions.gcd(ans,a[tmp+1])
        tmp+=1
    return ans
max_ans = 1
for i in range(1,n-1):
    pre_ans = fractions.gcd(calcGCD(0,i-1), calcGCD(i+1,n-1))
    max_ans = max(pre_ans, max_ans)
pre_ans = calcGCD(1,n)
max_ans = max(pre_ans, max_ans)
pre_ans = calcGCD(0,n-1)
max_ans = max(pre_ans, max_ans)

print(max_ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import copy

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

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

ans = 0
for i in range(n-1):
    tmp_list = copy.copy(a_list)
    tmp_list.pop(i)
    #print(tmp_list)
    tmp = gcd(*tmp_list)
    #print(tmp)
    if tmp > ans:
        ans = tmp
    
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n==1:
    print(10**9)
    exit()

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


if len(set(a)) == 1:
    print(a[0])
    exit()

sosu = []

if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        gcd_a = gcd(gcd_a, a[i])
    print(gcd_a)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []

    if is_prime(a[0]//gcd_a):
        gcd_a_ = a[1]//gcd_a
        for i in range(2, n):
            gcd_a_ = gcd(gcd_a_, a[i]//gcd_a)
        print(gcd_a_*gcd_a)
        exit()
    else:
        gcd_a_ = a[0]//gcd_a

    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n==1:
    print(10**9)
    exit()

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


if len(set(a)) == 1:
    print(a[0])
    exit()

sosu = []

if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        gcd_a = gcd(gcd_a, a[i])
    print(gcd_a)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []
    gcd_a_ = a[0]//gcd_a
    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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


if len(set(a)) == 1:
    print(a[0])
    exit()


sosu = []


if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        gcd_a = gcd(gcd_a, a[i])
    print(gcd_a)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []
    gcd_a_ = a[0]//gcd_a
    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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


if len(set(a)) == 1:
    print(a[0])
    exit()


sosu = []


if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        gcd_a = gcd(gcd_a, a[i])
    print(gcd_a)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []
    gcd_a_ = a[0]//gcd_a
    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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


if len(set(a)) == 1:
    print(a[0])
    exit()


sosu = []


if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        ans = gcd(gcd_a, a[i])
    print(ans)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []
    gcd_a_ = a[0]//gcd_a
    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
n,a=int(input()),list(map(int,input().split()))
if n==2:
  print(max(a));exit()
if n==3:
  print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])));exit()
ans=ans2=a[0]
for i in range(1,n):
  g=gcd(ans,a[i])
  if g!=ans:
    ans=g*ans2//gcd(g,ans2)
    ans2=gcd(g,ans2)
print(ans)

Submission status: Wrong Answer

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

m=int(10**4.5)
prime = []
is_prime = [True] * (m+1)
is_prime[0] = is_prime[1] = False
for n in range(2,m+1):
    if not is_prime[n]: continue
    prime.append(n)
    for i in range(2*n,m+1,n): is_prime[i] = False

from collections import defaultdict
D = [defaultdict(int) for _ in range(N)]
for i,a in enumerate(A):
    for p in prime:
        while a%p==0:
            D[i][p]+=1
            a//=p

from operator import itemgetter
ans=1
for p in prime:
    count = defaultdict(int)
    for d in D: count[d[p]]+=1
    cc=0
    for n,c in sorted(count.items(), key=itemgetter(0), reverse=True):
        cc+=c
        if cc >= N-1:
            ans *= p**n
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n=int(input())
a=list(map(int,input().split()))
if n==2:print(gcd(a[0],a[1]));exit()
left=[a[0]]
for i in range(1,n):left.append(gcd(left[-1],a[i]))
right=[a[n-1]]
for i in range(n-2,-1,-1):right.append(gcd(right[-1],a[i]))
right.reverse()
ans=max(right[1],left[n-2])
print(max(ans,max(gcd(left[i-1],right[i+1])for i in range(1,n-1))))

Submission status: Wrong Answer

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    A.insert(0, A[N-1])
    tmp = [0]*(N-1)
    for i in range(N-1):
        tmp[i] = uclid(A[i], A[i+1])+uclid(A[i+1], A[i+2])    
    index_min = tmp.index(min(tmp))
    tmp.pop(index_min)
    print(min(tmp)-uclid(A[index_min+1], A[index_min+2]) if N > 2 else uclid(A[0], A[1]))
main()

Submission status: Wrong Answer

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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


def factorize(x):
    i = 2
    while i * i <= x:
        while x % i == 0:
            yield i
            x //= i
        i += 1
    if x > 1:
        yield x


heaps = defaultdict(list)
for a in A:
    counter = Counter(factorize(a))
    for i, count in counter.items():
        heappush(heaps[i], count)
for i in list(heaps):
    if len(heaps[i]) < N - 1:
        del heaps[i]

ans = None


def update_ans(val):
    global ans
    if ans is None or val > ans:
        ans = val


for a in A:
    counter = Counter(factorize(a))
    g = None


    def update_g(val):
        global g
        if g is None:
            g = val
        else:
            g = g * val


    for i, h in heaps.items():
        if len(h) == N and i in counter:
            if len(h) >= 2 and h[0] == counter[i]:
                update_g(i ** h[1])
            else:
                update_g(i ** h[0])
        elif len(h) == N - 1 and i not in counter:
            update_g(i ** h[0])
    if g is not None:
        update_ans(g)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))
m = []
l = [0]
r = [0]
for i in range(n):
  l.append(fractions.gcd(l[i],a[i]))
  r.append(fractions.gcd(r[i],a[-i-1]))
r.reverse()
for i in range(1,n):
  m.append(fractions.gcd(l[i],r[i+1]))
print(max(m))

Submission status: Wrong Answer

Solution code:
import functools

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

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

N = int(input())
A = list(map(int,(input().split())))
L = [0]*N
R = [0]*N

for i in range(N):
    L[i] = gcd(A[0:i+1])
for i in range(N):
    R[i] = gcd(A[N-1-i:N])

p = []

for i in range(N):
    if i == 0:
        p.append(R[N-1])
    elif i == N-1:
        p.append(L[N-1])
    else:
        p.append( gcd([L[i-1], R[N-2-i]]) )

print(max(p))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
def resolve():
    N,=pin()
    A=sorted(list(pin()))
    from fractions import gcd
    from functools import reduce
    a=A[1:]
    A.pop(1)
    #print(a,A)
    x=reduce(gcd,a)
    y=reduce(gcd,A)
    print((max(x,y)))
    
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
7 6 8"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
12 15 18"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2
1000000000 1000000000"""
        output = """1000000000"""
        self.assertIO(input, output)


if __name__=="__main__":resolve()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

maxGCD = 0
for i in range(N):
    for j in range(N):
        if j == i:
            pass
        else:
            if i == 0:
                ans = A[1]
                ans = gcd(ans, A[j])
            else:
                ans = A[0]
                ans = gcd(ans, A[j])
    if maxGCD < ans:
        maxGCD = ans
print(maxGCD)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from itertools import combinations


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


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

    comb = list(combinations(A, N - 1))
    if N == 2:
        result = max(A)
    else:
        result = 0
    for c in comb:
        for i in range(1, len(c)):
            result = max(result, gcd(c[i - 1], c[i]))
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


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

def gcd_all(lst):
    g = gcd(lst[0], lst[1])
    for e in lst[2:]:
        g = gcd(g, e)
    return g


def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    if n == 2:
        print(max(alist))
    else:
        g = gcd(alist[0], alist[1])
        remove_cand = 1
        for i, a in enumerate(alist[2:], start=2):
            t = gcd(g, a)
            if t < g:
                remove_cand = i
            g = t

        # idx=0について書き換えと、remove_candを試す
        g0 = gcd_all(alist[1:])
        alist.pop(remove_cand)
        print(max(g0, gcd_all(alist)))


if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

Solution code:


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

def gcd_all(lst):
    g = gcd(lst[0], lst[1])
    for e in lst[2:]:
        g = gcd(g, e)
    return g


def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    if n == 2:
        print(max(alist))
    else:
        g = gcd(alist[0], alist[1])
        remove_cand = -1
        for i, a in enumerate(alist[2:], start=2):
            t = gcd(g, a)
            if t < g:
                remove_cand = i
            g = t

        if remove_cand == -1:
            # idx=2以降に減少要因はないので, idx=0, 1について書き換えを試す
            g0 = gcd_all(alist[1:])
            alist.pop(1)
            g1 = gcd_all(alist)
            print(max(g0, g1))
        else:
            alist.pop(remove_cand)
            print(gcd_all(alist))


if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcdl = [1]*N
gcdl[0] = A[0]

gcdr = [1]*N
gcdr[-1] = A[-1]

for i in range(1, N):
    gcdl[i] = gcd(gcdl[i-1], A[i])
    gcdr[N-i-1] = gcd(gcdr[N-i], A[N-i-1])

res = max(gcdl[N-1], gcdr[1])

for i in range(1, N-1):
    res = max(gcd(gcdl[i-1], gcdr[i+1]), res)

print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

class SegmentTree:
    def __init__(self, n, init_value, ide_ele):
        self.num = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.seg = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.seg[i + self.num - 1] = init_value[i]
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
    
    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
    
    def query(self, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 0:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res
    
    @staticmethod
    def segfunc(a, b):
        return gcd(a, b)


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    
    seg_tree = SegmentTree(N, A, 0)
    ans = -1
    for i in range(N):
        ans = max(ans, gcd(seg_tree.query(0, i), seg_tree.query(i + 1, N)))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import fractions

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

def calc_gcd(a, b):
    if a < b:
        temp = b
        b = a
        a = temp
    
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    
    return b

gcd = fractions.gcd(A[0], A[1])

for i in range(2, n - 1):
    gcd = fractions.gcd(gcd, A[i])

ans = gcd
for i in range(1, n - 1):
    gcd1 = A[i - 1]
    gcd2 = A[i + 1]
    for j in range(i - 1):
        gcd1 = fractions.gcd(gcd1, A[j])
    
    for j in range(i + 2, n - 1):
        gcd2 = fractions.gcd(gcd2, A[i])
    gcd = fractions.gcd(gcd1, gcd2)
    ans = max(ans, gcd)
    
print(ans)

Submission status: Wrong Answer

Solution code:

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

def calc_gcd(a, b):
    if a < b:
        temp = b
        b = a
        a = temp
    
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    
    return b

gcd = 0

for i in range(n - 1):
    gcd = calc_gcd(A[i], A[i + 1])

ans = gcd
for i in range(1, n - 1):
    gcd1 = A[i - 1]
    gcd2 = A[i + 1]
    for j in range(i - 1):
        gcd1 = calc_gcd(A[j], A[j + 1])
    
    for j in range(i + 1, n - 1):
        gcd2 = calc_gcd(A[i], A[i + 1])


    gcd = calc_gcd(gcd1, gcd2)
    ans = max(ans, gcd)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[0]
r=[0]
ans=0
from  fractions import gcd
for i in range(n-1):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(r[i],a[-1]-i))
for i in range(n):
    ans=max(ans,gcd(l[i],r[-1-i]))

print(ans)

Submission status: Wrong Answer

Solution code:
import functools

# 最大公約数
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

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

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

# i番目を取り去る
#ans = 0
#for i in range(N):
#   tmp_left = A[:i]
#   tmp_right = A[i+1:]
#   tmp_lr = tmp_left + tmp_right
#   tmp = gcd_list(tmp_lr)
#   ans = max(ans,tmp)
#print(ans)


left = [0]
right = [0]
for i in range(N):
    tmp_left = A[:i+1]
    tmp_right = A[i:]
    left.append(gcd_list(tmp_left))
    right.append(gcd_list(tmp_right))

ans = 0
for i in range(N):
    ans = max(ans,gcd(left[i-1],right[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
num = int(input())
numarray = [int(i) for i in input().split()]

result_f = numarray[:] + [0]
result_t = [0] + numarray[:]
for i in range(num):
    result_f[num-i-1] = fractions.gcd(result_f[num-i], result_t[num-i-1])
    result_t[i+1] = fractions.gcd(result_t[i], result_t[i+1])

gcd_result = []
for i in range(num):
    gcd_result.append(fractions.gcd(result_t[i], result_f[i+1]))

print(max(gcd_result))

Submission status: Wrong Answer

Solution code:
import fractions
num = int(input())
numarray = [int(i) for i in input().split()]

result_f = numarray[:] + [0]
result_t = [0] + numarray[:]
for i in range(num):
    result_f[num-i-1] = fractions.gcd(result_f[num-i], result_t[num-i])
    result_t[i+1] = fractions.gcd(result_t[i], result_t[i+1])

gcd_result = []
for i in range(num):
    gcd_result.append(fractions.gcd(result_t[i], result_f[i+1]))

print(max(gcd_result))

Submission status: Wrong Answer

Solution code:
import fractions
num = int(input())
numarray = [int(i) for i in input().split(" ")]
num_gcd_max = 1

result_f = numarray[:] + [0]
result_t = [0] + numarray[:]
for i in range(num):
    result_f[num-i-1] = fractions.gcd(result_f[num-i], result_t[num-i])
    result_t[i+1] = fractions.gcd(result_t[i], result_t[i+1])

gcd_result = [0 for i in range(num)]
for i in range(num):
    gcd_result[i] = fractions.gcd(result_t[i], result_f[i+1])

print(max(gcd_result))

Submission status: Wrong Answer

Solution code:
import fractions
num = int(input())
numarray = [int(i) for i in input().split(" ")]
num_gcd_max = 1

result = [0 for i in range(num)]
result[0] = numarray
for i in range(num-1):
    for j in range(num):
        result[j] = fractions.gcd(numarray[j-1], numarray[j])
    numarray = result[:]
print(max(result))

Submission status: Wrong Answer

Solution code:

num = int(input())
numarray = [int(i) for i in input().split(" ")]
num_gcd_max = 1

for i in range(num):
    del_num = numarray.pop(0)
    # numarrayの数字の最大公約数を探す
    num_gcd = numarray[0]
    for j in range(num-1):
        m = max(numarray[j-1], numarray[j])
        n = min(numarray[j-1], numarray[j])
        r = m % n
        while(not r==0):
            m = n
            n = r
            r = m % n
        # n: j番目とj+1番目の最大公約数
        num_gcd = min(num_gcd, n)
        if(num_gcd <= num_gcd_max):
            break
        # print(num_gcd, numarray, m, " ", n)
        
    numarray.append(del_num)
    num_gcd_max = max(num_gcd_max, num_gcd)
print(num_gcd_max)

Submission status: Wrong Answer

Solution code:

num = int(input())
numarray = [int(i) for i in input().split(" ")]
num_gcd_max = 1

for i in range(num):
    del_num = numarray.pop(0)
    # numarrayの数字の最大公約数を探す
    num_gcd = numarray[0]
    for j in range(num-1):
        m = max(numarray[j-1], numarray[j])
        n = min(numarray[j-1], numarray[j])
        r = m % n
        while(not r==0):
            m = n
            n = r
            r = m % n
        # n: j番目とj+1番目の最大公約数
        num_gcd = min(num_gcd, n)
        
    numarray.append(del_num)
    num_gcd_max = max(num_gcd_max, num_gcd)
print(num_gcd_max)

Submission status: Wrong Answer

Solution code:
n = input()
l = list(map(int, input().split()))
# l = list(map(int, "12 15 18".split()))

l.sort()

primes = []
for i in range(2, max(l)+1):
  isDivisible = False
  for prime in primes:
    if i % prime == 0:
      isDivisible = True
  if not isDivisible:
    primes.append(i)

table = []
for n in l:
  exps = [0]*len(primes)
  for i in range(len(primes)):
    prime = primes[i]
    while n != 0 and n % prime == 0:
      n /= prime
      exps[i] += 1
  table.append(exps)

#print(table)

minIndexes = []
for i in range(len(primes)):
  col = list(map(lambda x: x[i], table))
  m = min(col)
  t = []
  for j in range(len(col)):
    if col[j] == m:
      t.append(j)
  if len(t) != len(col):
    minIndexes.append(t)

#print("minIndexes", minIndexes)

counter = [0]*len(l)
for i in minIndexes:
  for j in i:
    counter[j] += 1

m = max(counter)

#print("counter", counter)

maxIndexes = []
for i in range(len(counter)):
  if counter[i] == m:
    maxIndexes.append(i)

# n が counter[n] 個
#print("maxIndexes", maxIndexes)

o = -1
for i in minIndexes:
  for j in i:
    #print("check ",j, " in ", maxIndexes)
    if o == -1 and j in maxIndexes:
      o = j

table.pop(o)

ans = 1
for i in range(len(primes)):
  col = list(map(lambda x: x[i], table))
  #print("prime", i)
  #print("col: ",col)
  #print("min: ",min(col))
  if min(col) != 0:
    ans *= primes[i]**min(col)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from fractions import gcd

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

max = 1
for i, k in combinations(a, 2):
    if gcd(i, k) > max:
        max = gcd(i, k)

print(max)

Submission status: Wrong Answer

Solution code:
import functools
import fractions
import copy

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

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

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

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

# print(l)
# print(r)

ans = 1
for i in range(i):
    ans = max(ans, gcd(l[i],r[i+1]))

print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce


def gcd(v1, v2):
    v3 = v1 % v2
    if v3 == 0:
        return v2
    return gcd(v2, v3)


def main():
    N = int(input())
    A = [int(v) for v in input().split()]

    max_gcd = max(reduce(gcd, A[1:]), reduce(gcd, A[:N-1]))

    for i in range(1, N - 1):
        v1 = reduce(gcd, A[:i])
        v2 = reduce(gcd, A[i + 1:])

        max_gcd = max(max_gcd, gcd(v1, v2))

    print(reduce(gcd, A))

    print(max_gcd)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

max_gcd = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        tmp = gcd(A[i],A[j])
        if tmp > max_gcd:
            max_gcd=tmp
print(max_gcd)

Submission status: Wrong Answer

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

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

max_gcd = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        tmp = gcd(A[i],A[j])
        if tmp > max_gcd:
            max_gcd=tmp
print(max_gcd)

Submission status: Wrong Answer

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

gcd_from_left = [a[0]]
gcd_from_right = [a[-1]]

for i in range(1, n):
    gcd_from_left.append(fractions.gcd(gcd_from_left[i - 1], a[i]))
    gcd_from_right.append(fractions.gcd(gcd_from_right[i - 1], a[n - 1 - i]))

ans = max(gcd_from_left[n - 2], gcd_from_right[n - 2])
for i in range(1, n - 1):
    ans = max(ans, fractions.gcd(gcd_from_left[i - 1], gcd_from_right[i - 1]))
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
import numpy as np
N = int(input())
B = list(map(int,input().split()))
B.sort()
memory = 0
C = np.array(B)
min_number = B[0]
if len(set(B)) < 3:
    print(B[-1])
    exit()
for i in make_divisors(min_number):
    if min_number % i == 0:
        if len(C[C % i != 0]) < 2:
                memory = i
                break
min_number = B[1]
for i in make_divisors(min_number):
    if min_number % i == 0:
        if len(C[C % i != 0]) < 2:
            if memory < i:    
                memory = i
            break
print(memory)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
B = list(map(int,input().split()))
B.sort()
memory = 0
C = np.array(B)
min_number = B[0]
if len(set(B)) < 3:
    print(B[-1])
    exit()
if len(C[C % min_number != 0]) < 2:
    memory = min_number
else:
    for i in reversed(range(1, int(min_number ** 0.5)+1)):
        if min_number % i == 0:
            if len(C[C % i != 0]) < 2:
                memory = i
                break
min_number = B[1]
if len(C[C % min_number != 0]) < 2:
    memory = min_number
else:
    for i in reversed(range(1, int(min_number ** 0.5)+1)):
        if min_number % i == 0:
            if len(C[C % i != 0]) < 2:
                if memory < i:
                    memory = i
                break
print(memory)

Submission status: Wrong Answer

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

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

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

ans = 0
l=len(a)
for i in range(l):
    b = a[0:i] + a[i+1:l]
    ans = max(ans, gcd_list(b))
    print(b)

print(ans)