Problem p02793 (python)

Fixed submission:
from fractions import gcd

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

lcm = 1
for i in range(n):
  lcm = lcm * a[i] // gcd(lcm, a[i])
lcm %= mod

sum_b = 0
for i in range(n):
  sum_b = (sum_b + lcm * pow(a[i], mod - 2, mod)) % mod
print(sum_b)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7
max_a = a.max()
sieve = [True] * (max_a // 2)
prime = [2]
p = 3
while p * p <= max_a:
  if sieve[p // 2 - 1]:
    prime.append(p)
    for i in range(p * p, max_a + 1, 2 * p):
      sieve[i // 2 - 1] = False
  p += 2
prime.extend([i for i in range(p, max_a + 1, 2) if sieve[i // 2 - 1]])
prime_dict = {p: idx for idx, p in enumerate(prime)}

pf = np.zeros((n, len(prime)), dtype=np.int)
for i in range(n):
  for j, p in enumerate(prime):
    if p * p > a[i]:
      break
    while a[i] % p == 0:
      a[i] //= p
      pf[i, j] += 1
  if a[i] > 1:
    pf[i, prime_dict[a[i]]] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b = 1
  for j, p in enumerate(prime):
    b = b * p ** b_pf[i, j] % mod
  b_sum = (b_sum + b) % mod
print(b_sum)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

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

divisor = a[0]
multiple = a[0]
for i in range(1, n):
  divisor = gcd(divisor, a[i])
  inv_divisor = pow(divisor, mod - 2, mod)
  multiple = (multiple * a[i] * inv_divisor) % mod

sum_b = 0
for i in range(n):
  sum_b = (sum_b + multiple * inv_divisor) % mod
print(sum_b)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7
max_a = a.max()
sieve = [True] * (max_a // 2)
prime = [2]
p = 3
while p * p <= max_a:
  if sieve[p // 2 - 1]:
    prime.append(p)
    for i in range(p * p, max_a + 1, 2 * p):
      sieve[i // 2 - 1] = False
  p += 2
prime.extend([i for i in range(p, max_a + 1, 2) if sieve[i // 2 - 1]])
len_prime = len(prime)

pf = np.zeros((n, len_prime), dtype=np.int)
for i in range(n):
  j = 0
  while prime[j] * prime[j] <= a[i]:
    while a[i] % prime[j] == 0:
      a[i] //= prime[j]
      pf[i, j] += 1
    j += 1
  if a[i] > 1:
    pf[i, prime.index(a[i])] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b = 1
  for j in range(len_prime):
    b = b * prime[j] ** b_pf[i, j] % mod
  b_sum = (b_sum + b) % mod
print(b_sum)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7
max_a = a.max()
sieve = [True] * (max_a // 2)
prime = [2]
p = 3
while p * p <= max_a:
  if sieve[p // 2 - 1]:
    prime.append(p)
    for i in range(p * p, max_a + 1, p):
      sieve[i // 2 - 1] = False
  p += 2
prime.extend([i for i in range(p, max_a + 1, 2) if sieve[i // 2 - 1]])
len_prime = len(prime)

pf = np.zeros((n, len_prime), dtype=np.int)
for i in range(n):
  j = 0
  while prime[j] * prime[j] <= a[i]:
    while a[i] % prime[j] == 0:
      a[i] //= prime[j]
      pf[i, j] += 1
    j += 1
  if a[i] > 1:
    pf[i, prime.index(a[i])] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b = 1
  for j in range(len_prime):
    b = b * prime[j] ** b_pf[i, j] % mod
  b_sum = (b_sum + b) % mod
print(b_sum)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7
max_a = a.max()
sieve = [True] * (max_a // 2)
prime = [2]
p = 3
while p * p <= max_a:
  if sieve[p // 2 - 1]:
    prime.append(p)
    for i in range(p * p, max_a + 1, p):
      sieve[i // 2 - 1] = False
  p += 2
prime.extend([i for i in range(p, max_a + 1, 2) if sieve[i // 2 - 1]])
len_prime = len(prime)

pf = np.zeros((n, len_prime), dtype=np.int)
for i in range(n):
  j = 0
  while prime[j] * prime[j] <= a[i]:
    while a[i] % prime[j] == 0:
      a[i] //= prime[j]
      pf[i, j] += 1
    j += 1
  if a[i] > 1:
    pf[i, prime.index(a[i])] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b_sum = (b_sum + np.prod(prime ** b_pf[i])) % mod
print(b_sum)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7

pf = np.zeros((n, a.max()//2), dtype=np.int)
for i in range(n):
  while a[i] % 2 == 0:
    a[i] //= 2
    pf[0] += 1
  d = 3
  while d <= np.int(np.sqrt(a[i])):
    while a[i] % d == 0:
      a[i] //= d
      pf[d//2] += 1
    d += 2
  if a[i] > 1:
    pf[a[i]//2] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b_sum += 2 ** b_pf[0] + np.arange(3, 2*pf.shape[1]+2, 2) ** b_pf[1:]
  b_sum %= mod
print(b_sum)