Problem p03061 (python)

Fixed submission:
#最大公約数を求める再帰関数-->計算量O(log(max(x))
def gcd1(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x-y, y)

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


#本文
N = int(input())
list_A = list(map(int, input().split()))

#配列初期化
list_gcd = [0] * N
list_gcd_rev = [0] * N

#以下　間違いを発見できず

##配列の最初のgcdを求める。定義
#list_gcd[0] = list_A[0]
#list_gcd_rev[N-1] = list_A[N-1]
##print (list_gcd, list_gcd_rev)

##配列にgcdを代入していく
#for i in range(1,N):
#    list_gcd[i] = gcd(list_gcd[i-1], list_A[i])
##print (list_gcd)
#for j in range(1,N):
#    list_gcd_rev[N-1-j] = gcd(list_gcd_rev[N-j], list_A[N-1-j])
##print (list_gcd_rev)

##print (list_gcd, list_gcd_rev)

##k番目までの両端からのgcdを求める
#if N == 2:
#    ans = gcd(list_gcd[0], list_gcd_rev[1])
#else:
#    ans = max(list_gcd[N-2], list_gcd_rev[1]) #両端の文字を除いたときの答え
##print (ans)
#for k in range(1,N-1):
#    a = list_gcd[k-1]
#    b = list_gcd_rev[k+1]
#    ans = max(ans, gcd(a, b))
#print (ans)

#以下、正答

for i in range(1,N):
    list_gcd[i]=gcd(list_gcd[i-1],list_A[i-1])
for i in range(N-1)[::-1]:
    list_gcd_rev[i]=gcd(list_gcd_rev[i+1],list_A[i+1])
Z = [gcd(list_gcd[i], list_gcd_rev[i]) for i in range(N)]
print (max(Z))

Buggy submission (verdict: Runtime Error):
#最大公約数を求める再帰関数-->計算量O(log(max(x))
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x-y, y)


#本文
N = int(input())
list_A = list(map(int, input().split()))

#配列初期化
list_gcd = [0] * N
list_gcd_rev = [0] * N

#以下　間違いを発見できず

##配列の最初のgcdを求める。定義
#list_gcd[0] = list_A[0]
#list_gcd_rev[N-1] = list_A[N-1]
##print (list_gcd, list_gcd_rev)

##配列にgcdを代入していく
#for i in range(1,N):
#    list_gcd[i] = gcd(list_gcd[i-1], list_A[i])
##print (list_gcd)
#for j in range(1,N):
#    list_gcd_rev[N-1-j] = gcd(list_gcd_rev[N-j], list_A[N-1-j])
##print (list_gcd_rev)

##print (list_gcd, list_gcd_rev)

##k番目までの両端からのgcdを求める
#if N == 2:
#    ans = gcd(list_gcd[0], list_gcd_rev[1])
#else:
#    ans = max(list_gcd[N-2], list_gcd_rev[1]) #両端の文字を除いたときの答え
##print (ans)
#for k in range(1,N-1):
#    a = list_gcd[k-1]
#    b = list_gcd_rev[k+1]
#    ans = max(ans, gcd(a, b))
#print (ans)

#以下、正答

for i in range(1,N):
    list_gcd[i]=gcd(list_gcd[i-1],list_A[i-1])
for i in range(N-1)[::-1]:
    list_gcd_rev[i]=gcd(list_gcd_rev[i+1],list_A[i+1])
Z = [gcd(list_gcd[i], list_gcd_rev[i]) for i in range(N)]
print (max(Z))

Buggy submission (verdict: Runtime Error):
#最大公約数を求める再帰関数-->計算量O(log(max(x))
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x-y, y)


#本文
N = int(input())
list_A = list(map(int, input().split()))

#配列初期化
list_gcd = [0] * N
list_gcd_rev = [0] * N

#配列の最初のgcdを求める。定義
list_gcd[0] = list_A[0]
list_gcd_rev[N-1] = list_A[N-1]
#print (list_gcd, list_gcd_rev)

#配列にgcdを代入していく
for i in range(1,N):
    list_gcd[i] = gcd(list_gcd[i-1], list_A[i])
#print (list_gcd)
for j in range(1,N):
    list_gcd_rev[N-1-j] = gcd(list_gcd_rev[N-j], list_A[N-1-j])
#print (list_gcd_rev)

#print (list_gcd, list_gcd_rev)

#k番目までの両端からのgcdを求める
if N == 2:
    ans = gcd(list_gcd[0], list_gcd_rev[1])
else:
    ans = max(list_gcd[N-2], list_gcd_rev[1]) #両端の文字を除いたときの答え
#print (ans)
for k in range(1,N-1):
    a = list_gcd[k-1]
    b = list_gcd_rev[k+1]
    ans = max(ans, gcd(a, b))
print (ans)

Buggy submission (verdict: Runtime Error):
#最大公約数を求める再帰関数-->計算量O(log(max(x))
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x-y, y)


#本文
N = int(input())
list_A = list(map(int, input().split()))

#配列初期化
list_gcd = [0] * N
list_gcd_rev = [0] * N

#配列の最初のgcdを求める。定義
list_gcd[0] = list_A[0]
list_gcd_rev[N-1] = list_A[N-1]
#print (list_gcd, list_gcd_rev)

#配列にgcdを代入していく
for i in range(1,N):
    list_gcd[i] = gcd(list_gcd[i-1], list_A[i])
#print (list_gcd)
for j in range(1,N):
    list_gcd_rev[N-1-j] = gcd(list_gcd_rev[N-j], list_A[N-1-j])
#print (list_gcd_rev)

#print (list_gcd, list_gcd_rev)

#k番目までの両端からのgcdを求める
if N == 2:
    ans = gcd(list_gcd[N-2], list_gcd_rev[1])
else:
    ans = max(list_gcd[N-2], list_gcd_rev[1]) #両端の文字を除いたときの答え
#print (ans)
for k in range(1,N-1):
    a = list_gcd[k-1]
    b = list_gcd_rev[k+1]
    ans = max(ans, gcd(a, b))
print (ans)

Buggy submission (verdict: Runtime Error):
#最大公約数を求める再帰関数-->計算量O(log(max(x))
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x-y, y)


#本文
N = int(input())
list_A = list(map(int, input().split()))

#配列初期化
list_gcd = [0] * N
list_gcd_rev = [0] * N

#配列の最初のgcdを求める。定義
list_gcd[0] = list_A[0]
list_gcd_rev[N-1] = list_A[N-1]
#print (list_gcd, list_gcd_rev)

#配列にgcdを代入していく
for i in range(1,N):
    list_gcd[i] = gcd(list_gcd[i-1], list_A[i])
#print (list_gcd)
for j in range(1,N,):
    list_gcd_rev[N-1-j] = gcd(list_gcd_rev[N-j], list_A[N-1-j])
#print (list_gcd_rev)

#print (list_gcd, list_gcd_rev)

#k番目までの両端からのgcdを求める
ans = max(list_gcd[N-2], list_gcd_rev[1]) #両端の文字を除いたときの答え
#print (ans)
for k in range(1,N-1):
    a = list_gcd[k-1]
    b = list_gcd_rev[k+1]
    ans = max(ans, gcd(list_gcd[k-1], list_gcd_rev[k+1]))
print (ans)

Buggy submission (verdict: Runtime Error):
#最大公約数を求める再帰関数-->計算量O(log(max(x))
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x-y, y)


#本文
N = int(input())
list_A = list(map(int, input().split()))

#配列初期化
list_gcd = [0] * N
list_gcd_rev = [0] * N

#配列の最初のgcdを求める。定義
list_gcd[0] = list_A[0]
list_gcd_rev[N-1] = list_A[N-1]
#print (list_gcd, list_gcd_rev)

#配列にgcdを代入していく
for i in range(1,N):
    list_gcd[i] = gcd(list_gcd[i-1], list_A[i])
#print (list_gcd)
for j in range(1,N,):
    list_gcd_rev[N-1-j] = gcd(list_gcd_rev[N-j], list_A[N-1-j])
#print (list_gcd_rev)

#print (list_gcd, list_gcd_rev)

#k番目までの両端からのgcdを求める
ans = max(list_gcd[N-2], list_gcd_rev[1]) #両端の文字を除いたときの答え
#print (ans)
for k in range(1,N-1):
    a = list_gcd[k-1]
    b = list_gcd_rev[k+1]
    ans = max(ans, gcd(list_gcd[k-1], list_gcd_rev[k+1]))
print (ans)