Problem p02793 (python)

Fixed submission:
import fractions
from functools import reduce

mod = 10**9 + 7

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = list(map(int, input().split()))
a_ = []
for i in range(n):
    a_.append(pow(a[i], mod - 2, mod))

num_lcm = lcm(*a) % mod
ans = 0
for i in range(n):
    ans = (ans + num_lcm * a_[i] % mod) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    lst, temp = [], n
    for i in range(2, int(n**0.5//1+1)):
        if temp %i ==0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            lst.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if lst == []:
        lst.append([n, 1])
    return lst

mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))

soinsu = {}
factrized_a = []
for i in range(n):
    lst = factorization(a[i])
    factrized_a.append(lst)
    for sosu, josu in lst:
        try:
            before_josu = soinsu[sosu]
        except KeyError:
            before_josu = 0
        soinsu[sosu] = max(before_josu, josu)

ans = 0
for i in range(n):
    lst = factrized_a[i]
    copied_soinsu = soinsu.copy()
    for sosu, josu in lst:
        copied_soinsu[sosu] -= josu
    bi = 1
    for sosu, josu in copied_soinsu.items():
        bi = bi * (sosu**josu) % mod
    ans = (ans + bi) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))

soinsu = [0 for _ in range(1001)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu[:]
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1001):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))

soinsu = [0 for _ in range(1001)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu.copy()
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1001):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))

soinsu = [0 for _ in range(1000)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu.copy()
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1000):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)