Problem p03061 (python)

Fixed submission:
def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x
n = int(input())
a = list(map(int,input().split()))

L,R = [0],[0]
for i in range(1,n+1): #L[i]は左i個,R[i]は右i個
    L.append(gcd(L[-1],a[i-1]))
    R.append(gcd(R[-1],a[n-i]))
print(max(gcd(L[i],R[n-i-1]) for i in range(n)))

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
    if x < y:
        x,y = y,x
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

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

def l(m): #左m個
    if m == 0:
        return 0
    else:
        return gcd(l(m-1),a[m-1])
def r(m):  #右m個
    if m == 0:
        return 0
    else:
        return gcd(r(m-1),a[n-m])
print(max([gcd(l(i),r(n-i-1)) for i in range(n)]))

Buggy submission (verdict: Runtime Error):
import fractions

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

def l(m):
    if m == 0:
        return 0
    else:
        return fractions.gcd(l(m-1),a[m-1])
def r(m):
    if m == 0:
        return 0
    else:
        return fractions.gcd(r(m-1),a[n-m])
print(max([fractions.gcd(l(i),r(n-i-1)) for i in range(n)]))

Buggy submission (verdict: Runtime Error):
import fractions

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

def l(m): #左m個
    if m == 0:
        return 0
    else:
        return fractions.gcd(l(m-1),a[m-1])
def r(m):  #右m個
    if m == 0:
        return 0
    else:
        return fractions.gcd(r(m-1),a[n-m])
max([fractions.gcd(l(i),r(n-i-1)) for i in range(n)])

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
m = 0
for i in range(n):
    b = a.copy()
    b[i:i+1] = []
    g = reduce(math.gcd,b)
    m = max(m,g)
print(m)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
m = 0
for i in range(n):
    b = a.copy()
    b[i:i+1] = []
    g = b[0]
    for j in range(n-1):
        g = math.gcd(g,b[j])
    m = max(m,g)
print(m)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    if a<b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

N = int(input())
A = list(map(int,input().split()))
def L(i):
    if i == 0 or i == 1:
        return 0
    else:
        return(gcd(L(i-1),A[i-2]))
def R(i):
    if i == N+1:
        return 0
    else:
        return(gcd(R(i+1),A[i-1]))
gcd_max = 0
for i in range(1,N+1):
    gcd_max = max(gcd_max,gcd(L(i),R(i+1)))
print(gcd_max)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    if a<b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

N = int(input())
A = list(map(int,input().split()))
def L(i):
    if i == 0 or i == 1:
        return 0
    else:
        return(gcd(L(i-1),A[i-2]))
def R(i):
    if i == N+1:
        return 0
    else:
        return(gcd(R(i+1),A[i-1]))
gcd_max = 0
for i in range(N):
    gcd_max = max(gcd_max,gcd(L(i),R(i+1)))
print(gcd_max)

Buggy submission (verdict: Runtime Error):
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
gcd_max = 0
for i in range(N):
    B = A.copy()
    B[i:i+1] = []
    gcd_max = max(gcd_max,reduce(gcd,B))
print(gcd_max)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
g_max = 0
for i in range(N):
    B = A.copy()
    B[i:i+1] = []
    g = reduce(math.gcd,B)
    if g_max < g:
        g_max = g
print(g_max)