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

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

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

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

print(result)

Submission status: Wrong Answer

Solution code:
n = list(map(int, input().split()))
A = list(map(int, input().split()))
print(max(A))

Submission status: Wrong Answer

Solution code:
import fractions

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


def mass_gcd(L):

    if len(L) == 1:
        return L[0]
    else:
        max_gcd = fractions.gcd(L[0], L[1])
    for i in range(1, len(L) - 1):
        max_gcd = max(max_gcd, fractions.gcd(L[i], L[i + 1]))
    return max_gcd

ans = 0
for i in range(0, N):
    left = A[:i]
    right = A[(i + 1):]
    if len(left) == 0:
        ans = max(ans, mass_gcd(right))
    elif len(right) == 0:
        ans = max(ans, mass_gcd(left))
    else:
        ans = max(ans, fractions.gcd(mass_gcd(left), mass_gcd(right)))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
N=int(input())
A=list(map(int, input().split()))
Z=0
ans=0
for i in range(N):
    if i==0:
        B=A.copy()
        B[0]=B[1]
        ans=functools.reduce(fractions.gcd, B)
 
 
    else :
        B=A.copy()
        B[i]=B[0]
        Z =functools.reduce(fractions.gcd, B)
        if ans >Z: break
 
    if ans >Z:
        ans=ans
    else:
        ans=Z
 
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

N = int(input()) # ignore
As = list(map(int, input().split()))
init_gcd = reduce(gcd, As, 0)
Bs = list(map(lambda x: x // init_gcd, As))
# print(Bs)

if N == 2:
    print(max(As[0], As[1]))
else:
    for b1idx, (b1, b2) in enumerate(zip(Bs, Bs[1:])):
        if b1idx == len(Bs) - 1:
            break
        x = gcd(b1, b2)
        if x == 1:
            if b1idx <= len(Bs) - 2:
                y = max(gcd(b2, Bs[b1idx + 2]), gcd(b1, Bs[b1idx + 2]))
                print(init_gcd * y)
            break

Submission status: Wrong Answer

Solution code:
import numpy as np
from fractions import gcd
from functools import reduce

n = int(input())

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

left = [a[0]] * n
for i in range(1, n):
    left[i] = gcd(left[i - 1], a[i])

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

if n == 2:
    print(max(a))
else:
    print(max(gcd(left[i], right[i + 1]) for i in range(n)))

Submission status: Wrong Answer

Solution code:
import fractions
import functools
N=int(input())
A=list(map(int, input().split()))
Z=0
ans=0
for i in range(N):
    if i==0:
        B=A.copy()
        B[0]=B[1]
        ans=functools.reduce(fractions.gcd, B)
 
 
    else :
        B=A.copy()
        B[i]=B[0]
        Z =functools.reduce(fractions.gcd, B)
        if ans > Z:
          break
 
    
    
    ans=Z
 
print(ans)

Submission status: Wrong Answer

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

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

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

# GCDの結合則を利用する
# 左端、右端からの累積GCDを求めておくと、Aiを取り除いた場合のGCDがすぐに計算できる。
# つまり、
# L(i): n=0,...,iまでのGCD 
# R(i): n=i,...,N-1までのGCD
# このとき、Aiを除いた全体のGCDは、GCD(L(i-1), R(i+1))で計算できる。

L = [0] * N
R = [0] * N

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

mx = 0
for i in range(N):
    if i == 0:
        v = R[1]
    elif i == N-1:
        v = L[N-1]
    else:
        v = R[i+1] + L[i-1]
    mx = max(v, mx)
print(mx)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N2 = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 3
    N2 = 2
    A = [1,1000000000,1000000000]

  x = 0
  for i in range(N2):
    if N == 1:
      tmp  = 1000000000
    elif N2 == 2 :
      tmp = max(A)
      # tmp = functools.reduce(fractions.gcd, A)
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


def main():

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

    gcds_r = [1] * N
    gcds_r[0] = A[0]
    for n in range(1, N):
        gcds_r[n] = fractions.gcd(gcds_r[n-1], A[n])

    gcds_l = [1] * N
    gcds_l[-1] = A[-1]
    for n in range(N-1)[::-1]:
        gcds_l[n] = fractions.gcd(gcds_l[n+1], A[n])

    max_gcd = 1
    for n in range(1, N-1):
        max_gcd = max(max_gcd, fractions.gcd(gcds_r[n-1], gcds_l[n+1]))

    max_gcd = max(max_gcd, gcds_l[1], gcds_r[N-1])

    print(max_gcd)  


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
from fractions import gcd
from functools import reduce

n = int(input())

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

left = [a[0]] * n
for i in range(1, n):
    left[i] = gcd(left[i - 1], a[i])

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

print(max(gcd(left[i], right[i + 1]) for i in range(n)))

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()]
AA = []
for i in A:
    if(not i in AA):
        AA.append(i)
AA.sort()
maxgcd = 0
if(len(AA)<=2):
    print(max(AA))
else:
    for i in range(len(AA)-1):
        maxgcd = max(maxgcd,gcd_list(AA[:i]+AA[i+1:]))

    print(maxgcd)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

N = int(input()) # ignore
As = list(map(int, input().split()))
init_gcd = reduce(gcd, As, 0)
Bs = list(map(lambda x: x // init_gcd, As))
print(Bs)

if N == 2:
    print(max(As[0], As[1]))
else:
    for b1idx, (b1, b2) in enumerate(zip(Bs, Bs[1:])):
        if b1idx == len(Bs) - 1:
            break
        x = gcd(b1, b2)
        if x == 1:
            if b1idx <= len(Bs) - 2:
                y = gcd(b1, Bs[b1idx + 2])
                print(y)
            break

Submission status: Wrong Answer

Solution code:
import fractions
import functools
N=int(input())
A=list(map(int, input().split()))
Z=0
ans=0
for i in range(N):
    if i==0:
        B=A.copy()
        B[0]=B[1]
        ans=functools.reduce(fractions.gcd, B)
 
 
    else :
        B=A.copy()
        B[i]=B[0]
        Z =functools.reduce(fractions.gcd, B)
 
 
    if ans >Z:
        break
    else:
        ans=Z
 
print(ans)

Submission status: Wrong Answer

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

n=int(input())
a=[int(x) for x in input().split()]
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)*-1]))
r = r[::-1]
m = []
for i in range(n-1):
    m.append(fractions.gcd(l[i],r[i+1]))
print(max(m))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(map(int,input().split()))
count=0
for i in range(max(c),0,-1):
  if i in c:
    for j in range(n):
      if c[j]%i!=0:
        count=count+1
      if count>=2:
        break
    if count==1 or count==0:
      print(i)
      break
    count=0

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import copy

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

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

#in
n=int(input())
v=list(map(int, input().split()))

maxi = 0

# おなじか？
if len(list(set(v))) == 1:
    maxi = (v[0])
elif len(v) == 2:
    maxi = (max(v))
# 書き換え 1
else:
    for i in range(n):
        listv = []
        listv = copy.copy(v)
        listv[i] = min(v) 
        listv[i] = max(listv)
        print(listv)
        print(v)
        listval = listv
        temp = gcd_list(listval)
        if temp> maxi:
            maxi = temp
#最大公約数


print(maxi)

# 書き換え 2

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = input().split(' ')
for i in range(N):
  A[i] = int(A[i])
smll = 0
for i in range(N-1):
  if A[smll]>A[i+1]:
    smll = i+1
def bai(x,y):
    b = x%y
    if b==0:
      return y
    else:
      return bai(y,b)
kobai = list(i for i in range(N))
for i in range(N):
  kobai[i] = bai(A[i],A[smll])
sml = 0
for i in range(N-1):
  if kobai[sml]>kobai[i+1]:
    sml = i+1
kobai.pop(sml)
sml = 0
for i in range(N-2):
  if kobai[sml]>kobai[i+1]:
    sml = i+1
print(kobai[sml])

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
Al = []
if len(A) >= 3:
    for lop in range(2,len(A),3):
        A1 = fractions.gcd(A[lop-2],A[lop-1])
        A2 = fractions.gcd(A[lop-2],A[lop])
        A3 = fractions.gcd(A[lop-1],A[lop])
        Al.append(max(A1,A2,A3))
    if len(A) % 3 > 0:
        A1 = fractions.gcd(A[len(A)-3],A[len(A)-2])
        A2 = fractions.gcd(A[len(A)-3],A[len(A)-1])
        A3 = fractions.gcd(A[len(A)-2],A[len(A)-1])
        Al.append(max(A1,A2,A3))
    
    if len(Al) == 1:
        print(Al[0])
    else:
        Al.pop( Al.index(min(Al)) )
        if len(Al) == 1:
            print(Al[0])
        else:
            buf = fractions.gcd(Al[0],Al[1])
            for lop in range(2,len(Al)):
                fractions.gcd(buf,Al[lop])
            print(buf)
else:
    print(max(A))

Submission status: Wrong Answer

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


N = int(input())
A = list(map(int, input().split()))
R = [0 for i in range(N - 1)]
L = [0 for i in range(N - 1)]
R[0] = A[0]
L[0] = A[-1]
for i in range(1, N - 1):
    R[i] = gcd(R[i - 1], A[i])
for j in range(1, N - 1):
    L[j] = gcd(L[j - 1], A[-1 - j])
t = 0
for i in range(N - 2):
    #print(R[i], L[N - 2 - i])
    t = max(t, gcd(R[i], L[i]))
print(max(t, R[N - 2], L[N - 2]))

Submission status: Wrong Answer

Solution code:
n = list(map(int, input().split()))
A = list(map(int, input().split()))
print(1000000000)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = input().split(' ')
for i in range(N):
  A[i] = int(A[i])
smll = 0
for i in range(N-1):
  if A[smll]>A[i+1]:
    smll = i+1
def bai(x,y):
    b = x%y
    if b==0:
      return y
    else:
      return bai(y,b)
kobai = list(i for i in range(N))
for i in range(N):
  kobai[i] = bai(A[i],A[smll])
sml = 0
for i in range(N-1):
  if kobai[sml]>kobai[i+1]:
    sml = i+1
print(sml)
kobai.pop(sml)
print(kobai)
sml = 0
for i in range(N-2):
  if kobai[sml]>kobai[i+1]:
    sml = i+1
print(kobai[sml])

Submission status: Wrong Answer

Solution code:
import fractions

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

max_A = max(A)
for i in range(N):
    gcd[i] = fractions.gcd(A[i], max_A)

min_idx = gcd.index(min(gcd))

gcd.pop(min_idx)

print(min(gcd))

Submission status: Wrong Answer

Solution code:
import sys


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


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

    g0 = A[1]
    for i in range(1, N):
        g0 = gcd(g0, A[i])

    g = A[0]
    B = []
    for a in A:
        g = gcd(a, g)
        B.append(g)

    i = B.index(g)
    A.pop(i)

    g = A[0]
    for a in A:
        g = gcd(g, a)

    return max(g, g0)


if __name__ == '__main__':
    print(main())

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()

left_n = [0 for _ in range(n)]
right_n = [0 for _ in range(n)]

left_n[0] = nums[0]
right_n[n-1] = nums[n-1]

for i in range(n-1):
    left_n[i+1] = gcd(left_n[i], nums[i+1])
    right_n[n-2-i] = gcd(right_n[n-1-i], nums[n-2-i])

print(left_n)
print(right_n)

maxgcd = 0
for i in range(n):
    if i == 0:
        maxgcd = max(maxgcd, right_n[1])
    if i == n-1:
        maxgcd = max(maxgcd, left_n[n-2])
    else:
        maxgcd = max(maxgcd, gcd(right_n[i+1], left_n[i-1]))

print(maxgcd)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def calc_gcd(*n):
  return reduce(fractions.gcd, n)

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

b = A[1]
gcd = A[0]
for i in range(N):
  ret = fractions.gcd(gcd, A[i])
  if gcd != ret:
    gcd = ret
    b = A[i]

B = A.copy()
B.remove(A[0])
A.remove(b)
print(max(calc_gcd(*A), calc_gcd(*B)))

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()

left_n = [0 for _ in range(n)]
right_n = [0 for _ in range(n)]

left_n[0] = nums[0]
right_n[n-1] = nums[n-1]

for i in range(n-1):
    left_n[i+1] = gcd(left_n[i], nums[i+1])
    right_n[n-2-i] = gcd(right_n[n-1-i], nums[n-2-i])

print(left_n)
print(right_n)

maxgcd = 0
for i in range(n):
    if i == 0:
        maxgcd = max(maxgcd, right_n[1])
    if i == n-1:
        maxgcd = max(maxgcd, left_n[n-2])
    else:
        maxgcd = max(maxgcd, gcd(right_n[i+1], left_n[i-1]))

print(maxgcd)

Submission status: Wrong Answer

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


def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y:
        while x % y:
            z = x % y
            x = y
            y = z
        else:
            return z
    else:
        return y


maxA = 0
for i in range(N-1):
    maxA = max(maxA, gcd(A[i], A[i+1]))
    maxA = max(maxA, gcd(A[-i], A[-i-1]))
print(maxA)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N2 = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    N2 = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N2):
    if N == 1:
      tmp  = 1000000000
    elif N2 == 2 :
      tmp = functools.reduce(fractions.gcd, A)
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            #divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                #divisors.append(n//i)
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1

    # divisors.sort()
    return divisors

if n == 2:
    print max(a[0],a[1])
else:
    for i in range(2):
        make_divisors(a[i])
    for i in reversed(range(2,len(a))):
        k = a[i]
        del_list = []
        for j in chk:
            if k % j == 0:
                chk[j] += 1
            if chk[j] < i:
                del_list.append(j)
        for j in del_list:
            del chk[j]

    answer = 0
    for i in chk:
        if int(chk[i]) >= n - 1 and i > answer:
            answer = i
    print answer

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
lis = list(map(int,input().split()))
lis.sort()
if n == 2:
  print(max(lis))
  exit()
li = [lis[0]]
lii = [lis[-1]]
for i in range(1,n):
  li.append(fractions.gcd(li[i-1],lis[i]))
  lii.insert(0,fractions.gcd(lii[-i],lis[-(i+1)]))
ans = 0
for i in range(n-2):
  ans = max(ans,fractions.gcd(li[i],lii[i+2]))
print(ans)

Submission status: Wrong Answer

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

def gcdlist(numlist):
    l = len(numlist)
    re = gcd(numlist[0], numlist[1])
    for i in range(2,l):
        re = gcd(re, numlist[i])
    return re

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

ans = 0

maxA = max(Alist)
for i in range(N):
    Ai = Alist[i]
    Alist[i] = maxA
    Agcd = gcdlist(Alist)
    if ans < Agcd:
        ans = Agcd
    Alist[i] = Ai

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = list(map(int,input().split()))
hard = A[0]*A[1]
easy = A[0]
del A[0]
while len(A) != 0:
  easyt = fractions.gcd(hard,A[0])
  if easyt < easy:
    easy = easyt
  hard = fractions.gcd(hard,A[0])
  del A[0]
print(easy)

Submission status: Wrong Answer

Solution code:
def GetBCG(A, ignore):
    Amin = min(A)
    B = []
    for index in range(len(A)):
        if index == ignore:
            continue

        Bi = A[index]
        count = 0
        if Bi % Amin == 0:
            count += 1
        else:
            B.append(Bi % Amin)

    if count >= 1:
        return Amin
    else:
        return GetBCG(B, -1)


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

AnsList = [GetBCG(InputList, i) for i in range(N)]

print(max(AnsList))

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()

left_n = [0 for _ in range(n)]
right_n = [0 for _ in range(n)]

left_n[0] = nums[0]
right_n[n-1] = nums[n-1]

for i in range(n-1):
    left_n[i+1] = gcd(left_n[i], nums[i+1])
    right_n[n-2-i] = gcd(right_n[n-1-i], nums[n-2-i])

maxgcd = 0
for i in range(n):
    if i == 0:
        maxgcd = max(maxgcd, right_n[1])
    if i == n-1:
        maxgcd = max(maxgcd, left_n[n-1])
    else:
        maxgcd = max(maxgcd, gcd(right_n[i+1], left_n[i-1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
l = list(map(int,input().split()))

#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


element = gcd(l[0], l[1])
if N > 2: 
    for i in range(2,N):
        element = gcd(element,l[i])
    

num = 2 * element
index = -1
for i in range(N):
    if l[i] % num != 0:
        index = i

li = []
for i in range(N):
    if i != index:
        li.append(l[i])

if len(li) == 1:
    print (li[0])
else:    
    element = gcd(li[0], li[1])
    if len(li) > 2:
        for i in range(2,len(li)):
            element = gcd(element,li[i])
            
    
    print(element)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N):
    if N == 1 : 
      tmp = 1000000000
    elif N == 2 :
      tmp = functools.reduce(fractions.gcd, A)
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Wrong Answer

Solution code:
import functools
import operator

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

result = 0
for i, _ in enumerate(A):
    print(i, _)
    factors = set()
    for j, a in enumerate(A):
        if i == j:
            continue
        factors_a = set()
        for n in range(1, a+1):
            if a%n == 0:
                factors_a.add(n)
                a /= n
        print("factors_a", factors_a)
        if len(factors) == 0:
            factors = factors_a
        else:
            factors &= factors_a
    print("factors", factors)
    if len(factors) > 0:
        result = max(result, functools.reduce(operator.mul, factors))
    print("---")

print(result)

Submission status: Wrong Answer

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


n = int(input())  # 数値
a = list(map(int, input().split()))  # 複数数値をリストに格納

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]))

if(n == 2):
    print(max(a[0], a[1]))
elif (n == 3):
    li.sort()
    print(li[2])
elif n == 4:
    mae1 = li[0]
    mae2 = li[1]
    mae3 = li[2]
    mae4 = li[3]
    usiro1 = li[-1]
    usiro2 = li[-2]
    usiro3 = li[-3]
    usiro4 = li[-4]
    li.sort()

    if (li[0] == mae1 and li[1] == mae2) or (li[0] == usiro1 and li[1] == usiro2):
        print(li[2])
    else:
        print(li[3])
else:
    mae1 = li[0]
    mae2 = li[1]
    mae3 = li[2]
    mae4 = li[3]
    usiro1 = li[-1]
    usiro2 = li[-2]
    usiro3 = li[-3]
    usiro4 = li[-4]

    li.sort()

    if (li[0] == mae1 and li[1] == mae3 and li[2] == mae4) or (li[0] == usiro1 and li[1] == usiro3 and li[2] == usiro4):
        print(li[3])
    elif (li[0] == mae2 and li[0] == mae1) or (li[0] == usiro2 and li[0] == usiro1):
        print(li[2])
    else:
        print(li[4])

Submission status: Wrong Answer

Solution code:
N = int(input()) #整数の数
lst =list(map(int, input().split()))
i = 1 #公約数候補
kari_ans = 0
ans = 1
A = max(lst)
while i <= A: #公約数候補iを動かす
#    print (i)
    count = 0 #割り切れなかった回数
    j = 0 #リストの場所
    while j < N and count < 2: #リストを前から順に確認,ダメな回数が2回になったら終わる
#        print ('A')
        if lst[j] % i != 0: #割り切れなかったら
            count +=1 #割り切れなかった回数を1回増やす
            if count == 2: #2回割り切れなかったら
                j = N #jをNまで増やす --> while分から抜けるため
                kari_ans = 0 #候補を0に戻す
#                print('B')
            else:
                kari_ans = i
#                print ('C')
#            else: #割り切れていたらリストの次を確認
        kari_ans = i
        j += 1
#        print('D')
#        print(j)
    ans = max(ans, kari_ans)
    i += 1 #公約数候補を1つ進める
print (ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import sys

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

if len(a) == 2:
  print(max(a))
  sys.exit()
  
gcd_a = functools.reduce(fractions.gcd, a)
a=[i//gcd_a for i in a]

cnt = 0
so = 0
gcd_0 = functools.reduce(fractions.gcd, a[1:])
for i in range(1,len(a)):
  if fractions.gcd(a[0],a[i]) == 1:
    so = i
    cnt+=1
    if cnt == 2:
      print(max(gcd_a,gcd_0)*gcd_a)
      sys.exit()
  
a_i = [i for i in a if i != a[so]]
gcd_i = functools.reduce(fractions.gcd, a_i)

print(max(gcd_0,gcd_i)*gcd_a)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def calc_gcd(*n):
  return reduce(fractions.gcd, n)

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

b = A[0]
gcd = A[0]
for i in range(N):
  ret = fractions.gcd(gcd, A[i])
  if gcd != ret:
    gcd = ret
    b = A[i]

B = A.copy()
B.remove(A[0])
A.remove(b)
print(max(calc_gcd(*A), calc_gcd(*B)))

Submission status: Wrong Answer

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

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

valueList = [a[0]]
maxList = []

g = a[0]
valueList.append(g)
g = a[1]
for k in range(1, n):
  g = gcd(g, a[k])
maxList.append(g)
  

for i in range(1,n):
  g = a[0]
  for j in range(i):
    g = gcd(g,a[j])
  valueList.append(g)
  g = valueList[i]
  for k in range(i+1, n):
    g = gcd(g, a[k])
  maxList.append(g)
    
print(max(maxList))

Submission status: Wrong Answer

Solution code:

N = int(input())
A = list(map(int, input().split()))
Amax = max(A)
count1 = 1
count2 = 2
count3 = 1

def f(n):
    return n%count2

for i in range(Amax-2):
    A2 = list(map(f, A))
    if sum(A2)==0:
        count1 = count1 * count2
    if A2.count(0)==len(A2)-1:
        count3 = count2
    count2 += 1
    
    
    
print(count1*count3)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

from fractions import gcd

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv_ref(N, A):
  
    ans = 0
    for i in range(N):
        cand = A[0] if i != 0 else A[1]
        for j, a in enumerate(A):
            if i == j:
                continue
            cand = gcd(cand, a)
            if cand <= ans:
                break
        ans = max(ans, cand)
        
    return ans


def eratosthenes(n):
    p = []
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p

# P = eratosthenes(int(math.sqrt(10**9))+1)

@mt
def slv(N, A):
    
    a0 = A[0]
    g0 = []
    for a in A:
        g0.append(gcd(a0, a))
    ans = 0
    for g in g0:
        c = 0
        for a in A:
            if gcd(a, g) == g:
                c += 1
        if c >= N-1:
            ans = max(ans, g)


    a0 = A[1]
    g0 = []
    for a in A:
        g0.append(gcd(a0, a))
    for g in g0:
        c = 0
        for a in A:
            if gcd(a, g) == g:
                c += 1
        if c >= N-1:
            ans = max(ans, g)
    return ans
    


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))

    # N = 10
    # A = [72, 96, 44, 48, 34, 58, 38, 34, 6, 81]

    # print(slv_ref(N, A))
    # print(slv(N, A))
    # # for _ in range(10000):
    # #     N = 10
    # #     A = [random.randint(1, 100) for _ in range(N)]
    # #     if slv_ref(N, A) != slv(N, A):
    # #         print(N)
    # #         print(A)
    # #         print(slv_ref(N, A))
    # #         print(slv(N, A))
    # #         break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            #divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                #divisors.append(n//i)
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1

    # divisors.sort()
    return divisors

if n == 2:
    print max(a[0],a[1])
else:
    for i in range(2):
        make_divisors(a[i])
    for i in reversed(range(2,len(a))):
        k = a[i]
        chk2 = chk
        for j in chk:
            if k % j == 0:
                chk[j] += 1
            if chk[j] < i:
                #del chk2[j]
                continue
        chk = chk2
    answer = 0
    for i in chk:
        if int(chk[i]) >= n - 1:
            answer = i
    print answer

Submission status: Wrong Answer

Solution code:
N = int(input())
As = [int(i) for i in input().split()]
def calc(a, b):
    r = a % b
    while(r != 0):
        a = b
        b = r
        r = a % b
    return b
answer = 0
for i in range(len(As)):
    As_copy = As.copy()
    res = As_copy.pop(i)
    if i == N-1:
        i = 0
    _ = As_copy.pop(i)
    print(res, As_copy)
    for j in As_copy:
        if i == j:
            continue
        temp = calc(res, j)
        print(res, j, temp)
        res = temp
    if res > answer:
        answer = res
        print('answer',answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import sys

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

if len(a) == 2:
  print(max(a))
  sys.exit()
  
gcd_a = functools.reduce(fractions.gcd, a)
a=[i//gcd_a for i in a]

cnt = 0
gcd_0 = functools.reduce(fractions.gcd, a[1:])
for i in range(1,len(a)):
  if fractions.gcd(a[0],a[i]) == 1:
    so = i
    cnt+=1
    if cnt == 2:
      print(max(gcd_a,gcd_0)*gcd_a)
      sys.exit()

if cnt == 0:
  print(gcd_a)
  sys.exit()
  
a_i = [i for i in a if i != a[so]]
gcd_i = functools.reduce(fractions.gcd, a_i)

print(max(gcd_0,gcd_i)*gcd_a)