Problem p03061 (python)

Fixed submission:
# 解けなかった...orz

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

def gcd(i, j):
    if i <= 0:
        return j
    elif j <= 0:
        return i

    while i != j:
        if i < j:
            j %= i
            if j == 0: return i
        else:
            i %= j
            if i == 0: return j
    return i

# M = [0] * N
L = [0] * (N+1)
R = [0] * (N+1)
# L[0] = 0
# R[N] = 0

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

res = max(gcd(L[i], R[i+1]) for i in range(N))
print(res)

Buggy submission (verdict: Runtime Error):
# 解けなかった...orz
from math import gcd

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

def gcd(i, j):
    if i <= 0:
        return j
    elif j <= 0:
        return i

    while i != j:
        if i < j:
            j %= i
            if j == 0: return i
        else:
            i %= j
            if i == 0: return j
    return i

# M = [0] * N
L = [0] * (N+1)
R = [0] * (N+1)
# L[0] = 0
# R[N] = 0

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

res = max(gcd(L[i], R[i+1]) for i in range(N))
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [N] * (B[0]+1)
t = B[-1]//2-1
t = t if t > 0 else 0
for d in range(B[0], t, -1):
    for b in B:
        if b % d == 0:
            counts[d] -= 1
            if d != b // d:
                counts[b//d] -= 1

    if counts[d] < 2:
        ans = d
        break

if ans == 1:
    for i in range(B[-1]//2, 0, -1):
        if counts[i] < 2:
            ans = i
            break

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = np.full(B[0]+1, N)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] -= 1
            if d != b // d:
                counts[b//d] -= 1

    if counts[d] < 2:
        ans = d
        break

if ans == 1:
    for i in range(B[-1]//2, 0, -1):
        if counts[i] < 2:
            ans = i
            break

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [N] * (B[0]+1)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] -= 1
            if d != b // d:
                counts[b//d] -= 1

    if counts[d] < 2:
        ans = d
        break

if ans == 1:
    for i in range(B[-1]//2, 0, -1):
        if counts[i] < 2:
            ans = i
            break

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [0] * (B[0]+1)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] += 1
            if d != b // d:
                counts[b//d] += 1

    if counts[d] >= N-1:
        ans = d
        break

if ans == 1:
    for i in range(B[0]//2, 0, -1):
        if counts[i] >= N-1:
            ans = i

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [0] * (B[0]+1)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] += 1
            if d != b // d:
                counts[b//d] += 1

    if counts[d] >= N-1:
        ans = d
        break

if ans == 1:
    print(counts)
    for i in range(B[0]//2, 0, -1):
        if counts[i] >= N-1:
            ans = i

print(ans)