Problem p02793 (python)

Fixed submission:
import math
from collections import defaultdict

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

divisor_primes = defaultdict(int)

def prime_factrizer(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

for a in A:
    factrized_a = prime_factrizer(a)
    for prime in factrized_a:
        divisor_primes[prime[0]] = max(divisor_primes[prime[0]],prime[1])

invs = [1] * (max(A) + 1)
for i in range(2, max(A) + 1):
    invs[i] = mod - invs[mod % i] * (mod//i) % mod

lcm = 1
for key in divisor_primes.keys():
    power = divisor_primes[key]
    div = 1
    for i in range(power):
        div *= key
        div %= mod
    lcm *= div

ans = 0

for a in A:
    ans += invs[a]
    ans %= mod
ans *= lcm
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]
 
 
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
 
 
mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]
 
Z = 1
for n in divs_set:
    Z = Z * (n ** divs_powers[n])
 
B = [0] * N
for i, a in enumerate(A):
    B[i] = int(Z / a) % (10 ** 9 + 7)
 
print(int(sum(B)) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]


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


mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]

Z = 1
for n in divs_set:
    Z = Z * (n ** divs_powers[n])

B = [0] * N
for i, a in enumerate(A):
    B[i] = int(Z / a) % (10 ** 9 + 7)

print(int(sum(B)) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
N=input()
A = [int(a) for a in input().split()]

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

mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]

Z = 1
for n in divs_set:
    Z = Z*(n**divs_powers[n])

B = [0]*N
for i, a in enumerate(A):
    B[i] = int(Z/a)%(10**9+7)

print(B)
print(int(sum(B))%(10**9+7))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]

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

mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]

Z = 1
for n in divs_set:
    Z = Z*(n**divs_powers[n])

B = [0]*N
for i, a in enumerate(A):
    B[i] = int(Z/a)

print(B)
print(int(sum(B) % (10**9+7)))