Problem p02793 (python)

Fixed submission:
import fractions
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

p = 10**9+7

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

lcm = lcm_list(A)

B = [lcm//i for i in A]

print(sum(B)%p)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

primes = sieve(10**3)

def primeFactorization(n):
    ans = []
    temp = n
    for p in primes:
        while temp%p == 0:
            ans.append(p)
            temp /= p
    if temp > 1:
        ans.append(temp)
    return collections.Counter(ans)

AFactorized = list(map(primeFactorization, A))

lcm = collections.Counter()
for a in AFactorized:
    for p, n in a.items():
        lcm[p] = max(lcm[p], n)

lcm_val = 1
for p, n in lcm.items():
    lcm_val *= pow(p, n, mod)

ans = 0
for a in A:
    ans += lcm_val * pow(a, mod-2, mod)
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

primes = sieve(10**3)

def primeFactorization(n):
  ans = []
  temp = n
  for p in primes:
    while temp%p == 0:
      ans.append(p)
      temp /= p
  if temp > 1:
    ans.append(temp)
  return collections.Counter(ans)

AFactorized = list(map(primeFactorization, A))

lcm = collections.Counter()
for a in AFactorized:
    for p, n in a.items():
        if n > lcm.get(p, 0):
            lcm[p] = n

lcm_val = 1
for p, n in lcm.items():
    lcm_val *= pow(p, n, mod)

ans = 0
for a in A:
    ans += lcm_val * pow(a, mod-2, mod)
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
import numpy as np
from functools import reduce
from operator import mul

N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        for j in range(i*2, n+1):
            if j%i == 0:
                is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

primes = sieve(max(A))

def primeFactorization(n):
    temp = n
    ans = [0 for _ in range(len(primes))]
    for i in range(len(primes)):
        while temp%primes[i] == 0:
            temp /= primes[i]
            ans[i] += 1
    return ans

AFactorized = list(map(primeFactorization, A))

lcm = [0 for _ in range(len(primes))]
for i in AFactorized:
    lcm = np.maximum(lcm, i)

B = [lcm-a for a in AFactorized]

ans = 0
for b in B:
    ans += reduce(mul, primes**b%mod)
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
import numpy as np
from functools import reduce
from operator import mul

N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        for j in range(i*2, n+1):
            if j%i == 0:
                is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

primes = sieve(A)
# primes = sieve(int(max(A)**0.5)+1)

def primeFactorization(n):
    temp = n
    ans = [0 for _ in range(len(primes))]
    for i in range(len(primes)):
        while temp%primes[i] == 0:
            temp /= primes[i]
            ans[i] += 1
    return ans

AFactorized = list(map(primeFactorization, A))

lcm = [0 for _ in range(len(primes))]
for i in AFactorized:
    lcm = np.maximum(lcm, i)

B = [lcm-a for a in AFactorized]

ans = 0
for b in B:
    ans += reduce(mul, primes**b%mod)
    ans %= mod

print(ans)

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

N = int(input())
A = list(map(int, input().split()))

p = 10**9+7

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

lcm = lcm_list(A)

B = [lcm//i for i in A]

print(sum(B)%p)

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

N = int(input())
A = list(map(int, input().split()))

p = 10**9+7

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

lcm = lcm_list(A)

B = [lcm//i for i in A]

print(sum(B))