Problem:


Score : 500 points

Problem Statement

Given are N positive integers A_1,...,A_N.

Consider positive integers B_1, ..., B_N that satisfy the following condition.

Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.

Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.

Since the answer can be enormous, print the sum modulo (10^9 +7).

Constraints

1 \leq N \leq 10^4

1 \leq A_i \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).

Sample Input 1

3
2 3 4

Sample Output 1

13

Let B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.

Sample Input 2

5
12 12 12 12 12

Sample Output 2

5

We can let all B_i be 1.

Sample Input 3

3
1000000 999999 999998

Sample Output 3

996989508

Print the sum modulo (10^9+7).



Sample input:
3
2 3 4


Sample output:
13

Submission status: Runtime Error

Solution code:
import numpy as np
#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return a/gcd(a,b)*b

LCM=lcm(A[0],A[1])
#LCM%=mod
for i in range(2,N):
  LCM=lcm(LCM, A[i])
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  ans%=mod

print(int(ans%mod))

Submission status: Runtime Error

Solution code:
import numpy as np
#かけて最小公倍数になる　そのために必要な数がB
from math import gcd
N=int(input())
mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return (a*b)/gcd(a,b)

LCM=lcm(A[0],A[1])
#LCM%=mod
for i in range(2,N):
  LCM=lcm(LCM, A[i])
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  ans%=mod

print(int(ans%mod))

Submission status: Runtime Error

Solution code:
import numpy as np
#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return (a*b)/gcd(a,b)

LCM=lcm(A[0],A[1])
#LCM%=mod
for i in range(2,N):
  LCM=lcm(LCM, A[i])
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  ans%=mod

print(int(ans%mod))

Submission status: Runtime Error

Solution code:
import numpy as np
#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return (a*b)/gcd(a,b)

LCM=lcm(A[0],A[1])
#LCM%=mod
for i in range(2,N):
  LCM=lcm(LCM, A[i])
  #LCM%=mod
  
#print(LCM)
A=np.array(A)
print(int(((LCM/A)%mod).sum()%mod))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

import math
l = 1
for val in A:
    l = (l * val // math.gcd(val, l))
#print(l)

ans = 0
for val in A:
    ans = (ans + l // val) % MOD
print(ans)

Submission status: Runtime Error

Solution code:
def lcm(a, b):
    from math import gcd

    return a // gcd(a, b) * b


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    x = 1

    for e in a:
        x = lcm(x, e)

    ans = 0
    for e in a:
        ans += x // e

    print(ans % int(1e9 + 7))


main()

Submission status: Runtime Error

Solution code:
import numpy as np

def resolve():
  n = int(input())
  a = np.array(list(map(int, input().split())))
  l = np.lcm.reduce(a)
  print(np.sum(l // a) % 1000000007)

  return

if __name__ == "__main__":
  resolve()

Submission status: Runtime Error

Solution code:
from math import gcd
def lcm(x, y):
    return x * y // gcd(x, y)

n = int(input())
a = list(map(int,input().split()))
lc = a[0]
for i in a[1:]:lc=lcm(lc,i)
res=sum(lc//i for i in a)%(10**9+7)
print(res)

Submission status: Runtime Error

Solution code:
from math import gcd
mod = 10**9 +7
n = int(input())
a = list(map(int, input().split()))
r = a[0]
for i in range(1, n):
    r = r*a[i]//gcd(r, a[i])
result = 0
for i in a:
    result = (result+r//i)%mod
print(result)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
n=int(input())
a=list(map(int,input().split()))
t=1
for i in a:
    t=lcm(i,t)
ans=0
mod=1000000007
for i in a:
    ans=ans+(t//i)
    ans=ans%mod
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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

n = int(input())
a = list(map(int, input().split()))

l = lcm(a)
answer = 0
for aa in a:
    answer += l // aa
    answer = answer % (10 ** 9 + 7)

print(answer)

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, readline().split()))

    def enum_primes(n):
        flag_num = (n + 1) // 2
        prime_flag = [True] * flag_num

        for i in range(1, int(n ** 0.5) + 1, 2):
            if prime_flag[i]:
                p = 2 * i + 1
                for j in range(2 * i * (i + 1), flag_num, p):
                    prime_flag[j] = False

        primes = [2]
        temp = [i * 2 + 1 for i in range(1, flag_num) if prime_flag[i]]
        primes.extend(temp)

        return primes

    primes = enum_primes(max(a))

    def factorization(n):
        factors = []
        lim = int(n ** 0.5) + 5

        if n in primes:
            return Counter([n])

        for i in primes:
            while n % i == 0:
                factors.append(i)
                n //= i
            if n == 1:
                return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = {1: 1}

    for fac in a_fac:
        for key, value in fac.items():
            lcm[key] = max(lcm.get(key, 0), value)

    ans = 0

    for fac in a_fac:
        temp = 1
        for key, value in lcm.items():
            p = value - fac.get(key, 0)
            temp *= pow(key, p)
            temp %= MOD
        ans += temp
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, readline().split()))

    def factorization(n):
        factors = []

        if n < 2:
            return n

        while n % 2 == 0:
            factors.append(2)
            n //= 2

        for i in range(3, int(n ** 0.5) + 5, 2):
            while n % i == 0:
                factors.append(i)
                n //= i
        if n != 1:
            factors.append(n)

        return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = Counter([1])

    for i, fac in enumerate(a_fac):
        add_temp = fac - lcm
        add = Counter({key: value for key, value in add_temp.items() if value > 0})
        lcm += add

    b = [0] * n

    for i, fac in enumerate(a_fac):
        b_fac = lcm - fac
        temp = 1
        for key, value in b_fac.items():
            temp *= pow(key, value, MOD)
            temp %= MOD
        b[i] = temp

    ans = 0
    for elem in b:
        ans += elem
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, readline().split()))

    def factorization(n):
        factors = []

        if n < 2:
            return n

        while n % 2 == 0:
            factors.append(2)
            n //= 2

        for i in range(3, int(n ** 0.5) + 5, 2):
            while n % i == 0:
                factors.append(i)
                n //= i
        if n != 1:
            factors.append(n)

        return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = Counter([1])

    for i, fac in enumerate(a_fac):
        add_temp = fac - lcm
        add = {key: value for key, value in add_temp.items() if value > 0}
        lcm += add

    b = [0] * n

    for i, fac in enumerate(a_fac):
        b_fac = lcm - fac
        temp = 1
        for key, value in b_fac.items():
            temp *= pow(key, value, MOD)
            temp %= MOD
        b[i] = temp

    ans = 0
    for elem in b:
        ans += elem
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int,readline().split()))

    def factorization(n):
        factors = []

        if n < 2:
            return n

        while n % 2 == 0:
            factors.append(2)
            n //= 2

        for i in range(3, int(n ** 0.5) + 5, 2):
            while n % i == 0:
                factors.append(i)
                n //= i
        if n != 1:
            factors.append(n)

        return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = Counter([1])

    for i, fac in enumerate(a_fac):
        add = +(fac - lcm)
        lcm += add

    b = [0] * n

    for i, fac in enumerate(a_fac):
        b_fac = lcm - fac
        temp = 1
        for key, value in b_fac.items():
            temp *= pow(key, value, MOD)
            temp %= MOD
        b[i] = temp

    ans = 0
    for elem in b:
        ans += elem
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import gcd

n = int(readline())
a = list(map(int, readline().split()))
ans = 0
gcd_ans = a[0]
lcm_ans = a[0]
mod = 10 ** 9 + 7
for i in range(1, n):
    gcd_ans = gcd(lcm_ans, a[i])
    lcm_ans = lcm_ans * a[i] // gcd_ans
for i in range(n):
    ans += lcm_ans // a[i]
    ans %= mod
print(ans % mod)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a>b:
        return gcd(b,a)
    if a==0:
        return b
    return gcd(b-a*(b//a),a)
def lcm(x,y):
    return (x*y)//gcd(x,y)
N=int(input())
A=list(map(input().split()))
s=1
for a in A:
    s=lcm(s,a)
ans=0
for a in A:
    ans+=s//a
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a>b:
        return gcd(b,a)
    if a==0:
        return b
    return gcd(b-a*(b//a),a)
def lcm(x,y):
    return (x*y)//gcd(x,y)
N=int(input())
A=list(map(input().split()))
s=1
for a in A:
    s=lcm(s,i)
ans=0
for a in A:
    ans+=s//i
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
mod = 10 ** 9 + 7

def gcd(a, b):
    if not(b):
        return a
    return gcd(b, a % b)

n = int(input())
s = [0 for i in range(n)]
g = 0
k = 0
s = [int(i) for i in input().split()]
ans = 0
for i in range(1, n):
    if not(k):
        g = gcd(s[i], s[i - 1])
        k = s[i] * s[i - 1] / g
    else:
        g = gcd(k, s[i])
        k = k * s[i] / g
for i in range(n):
    ans += int(k / s[i])
print(int(ans) % mod)

Submission status: Runtime Error

Solution code:
def lcm(a, b):
    ca = a
    ca = b
    while b:
        a %= b
        a, b = b, a
    gcd = a
    return ca * cb // gcd


n = int(input())
a = list(map(int, input().split(" ")))
alcm = a[0]
for i in a:
    alcm = lcm(alcm, i)

tot = 0
for num in a:
    tot += alcm // num

print(tot % 1000000007)

Submission status: Runtime Error

Solution code:
from collections import deque, Counter, defaultdict
from functools import lru_cache
from itertools import permutations
from heapq import (
    heappush,
    heappop,
    heapreplace,
    heappushpop,
    heapify,
    merge,
    nlargest,
    nsmallest,
)
from statistics import mean, median, mode


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


n = int(input())
a = list(map(int, input().split(" ")))

clcm = 1
for num in a:
    clcm = lcm(clcm, num)

tot = 0
for num in a:
    tot += clcm // num

print(int(tot % (1e9 + 7)))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
import sys
sys.setrecursionlimit(10**8)

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


def lcm(numbers):
    return reduce(lcm2, numbers, 1)


n = int(input())
a = list(map(int, input().split()))

b = lcm(a)

mod = 10 ** 9 + 7
total = 0
for v in a:
    total+= (b / v)
    total %= mod

print(int(total))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce


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


def lcm(numbers):
    return reduce(lcm2, numbers, 1)


n = int(input())
a = list(map(int, input().split()))

b = lcm(a)

mod = 10 ** 9 + 7
total = 0
for v in a:
    total+= (b / v)
    total %= mod

print(int(total))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


def lcm(numbers):
    return reduce(lcm2, numbers, 1)


n = int(input())
a = list(map(int, input().split()))

b = lcm(a)

mod = 10 ** 9 + 7
total = 0
for v in a:
    total+= (b / v)
    total %= mod

print(int(total))

Submission status: Runtime Error

Solution code:
import fractions

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

x=int(input())
a=list(map(int, input().split()))
ans=0
chk=lcm(a[0],a[1])
for i in range(x):
	chk=lcm(chk,a[i])
for i in range(x):
	ans=ans+(chk//a[i])
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
from math import gcd

def lcm(a,b):
    return a*(b//gcd(a,b))

mod=10**9+7

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

L=A[0]
for i in range(1,n):
    L=lcm(L,A[i])
L%=mod

ans=0
for i in range(n):
    ans+=(L//A[i])%mod
print(ans)

Submission status: Runtime Error

Solution code:
mod=10**9+7
from math import sqrt
n=int(input())

A=list(map(int,input().split()))
N=[0]*(10**3+1)
def soi(n):
    cnt_2=0
    while n%2==0:
        n//=2
        cnt_2+=1
    N[2]=max(N[2],cnt_2)
    for j in range(3,int(sqrt(n))+1,2):
        cnt_j=0
        while n%j==0:
            n//=j
            cnt_j+=1
        N[j]=max(N[j],cnt_j)
    if n!=1:
        N[n]=max(N[n],1)

for i in range(n):
    soi(A[i])
L=1
for i in range(1,10**3+1):
    L*=((i)**(N[i]))%mod
ans=0
for i in range(n):
    ans+=(L*pow(A[i],mod-2,mod))%mod
print(ans)

Submission status: Runtime Error

Solution code:
#from fractions import gcd
from math import gcd

def lcm(m, n): return m * n // gcd(m, n)

n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])

mulab %= MOD
ans = 0
for i in range(n):
    #フェルマーの小定理
    ans = ans + mulab * pow(a[i], MOD-2, MOD)
    ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from functools import reduce
import math

MOD = 1000000007  # type: int

GCD_CACHE = {}


def gcd(x, y):
    if (x, y) in GCD_CACHE:
        return GCD_CACHE[(x, y)]
    d = math.gcd(x, y)
    GCD_CACHE[(x, y)] = d
    return d


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


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


def solve(N: int, A: "List[int]"):
    m = lcm(*A) % MOD
    sum = 0
    for a in A:
        sum = (sum + m*pow(a, MOD-2, MOD)) % MOD
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]


NN = 10 ** 6 + 100
primes = []
isprime = [True for _ in range(NN + 1)]
min_factor = [-1 for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    min_factor[i] = i
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False
        if min_factor[j] == -1:
            min_factor[j] = i
def prime_factrize(n):
    res = []
    while n != 1:
        prime = min_factor[n]
        exp = 0
        while min_factor[n] == prime:
            exp += 1
            n //= prime
        res.append([prime, exp])
    return res


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        try:
            idx = [ll[k][0] for k in range(len(ll))].index(aa[j][0])
            ll[idx][1] = max(ll[idx][1], aa[j][1])
        except:
            ll.append(aa[j])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1])
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def lcm():
    ans=l[0]*l[1]//gcd(l[0],l[1])
    for i in range(2,len(l)):
        ans=ans*l[i]//gcd(ans,l[i])
    return ans
n=int(input())
l=list(map(int,input().split()))
s=0
ans=lcm()
for i in l:
    s+=(ans//i)%(10**9+7)
print(s%(10**9+7))

Submission status: Runtime Error

Solution code:
from math import gcd


def lcm(a, b):
    return a // gcd(a, b) * b


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

l = 1
for i in A:
    l = lcm(l, i)

MOD = 1000000007

ans = 0
for a in A:
    ans += l // a
    ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd


def lcm(a: int, b: int) -> int:
    return a // gcd(a, b) * b


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

l = 1
for i in A:
    l = lcm(l, i)

MOD = 1000000007

ans = 0
for a in A:
    ans += l // a
    ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
INF=10**9+7
import fractions
d=fractions.gcd(a[0],a[1])
m=a[0]*a[1]//d
for i in range(n-2):
    d=fractions.gcd(m,a[i+2])
    m=m*a[i+2]//d
ans=0
for i in range(n):
    ans=(ans+(m//a[i]))%INF
print(ans)

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
a = [int(x) for x in input().split()]
if n==1:
    print(1)
    sys.exit()
li = [0]*(10**3+1)
lcm = 1
for k in range(n):
    z = a[k]
    for i in range(2,int(z**0.5)+1):
        x = 0
        while z%i==0:
            x += 1
            z//=i
        if li[i]<x:
            if li[i]==0:
                li[i] = x
            else:
                lcm //= ((-1)*li[i])
                li[i] = x
    if z!=1 and li[z]==0:
        li[z] = -z
        lcm *= z

for i in range(2,10**3+1):
    if li[i]>0:
        lcm *= i*li[i]

mod = 10**9+7
ans = 0
for i in range(n):
    ans = (ans + lcm//a[i])%mod
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
mod = 10**9+7
n = int(input())
a = list(map(int(input().split())))
ans = 0
l = 1
for i in range(n):
    l = l*a[i]//gcd(l,a[i])
for i in a:
    ans = (ans + l*pow(i,mod-2,mod)) % mod
print(ans)

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
MOD = 10**9+7
def prime_table(n):
  prime = [2]
  limit = int(n**0.5)
  data = [i+1 for i in range(2,n,2)]
  isprime = [0]*(n+1)
  isprime[2] = 1
  min_factor = [0 if i%2 != 0 else 2 for i in range(n+1)]
  while True:
    p = data[0]
    prime.append(p)
    isprime[p] = 1
    pdata,data = data,[]
    for e in pdata:
      if e%p != 0:
        data.append(e)
      else:
        min_factor[e] = p
    if limit <= p:
      for i in data:
        isprime[i] = 1
        min_factor[i] = i
      return prime + data,isprime,min_factor
def modinv(a,m=MOD):
  b,u,v = m,1,0
  while b:
    t = a//b
    a,u = a-t*b,u-t*v
    a,b,u,v = b,a,v,u
  u %= m
  if u < 0:
    u += m
  return u
ma = max(a)
data,isprime,min_factor = prime_table(ma)
prime = [0] * (ma+1)
for i in a:
  d = defaultdict(int)
  while isprime[i] == 0:
    d[min_factor[i]] += 1
    i = i // min_factor[i]
  d[i] += 1
  for j,k in d.items():
    prime[j] = max(prime[j],k)
lcm = 1
for i in range(ma+1):
  if prime[i] != 0:
    lcm = (lcm*pow(i,prime[i],MOD))%MOD
c = 0
for i in a:
  c += lcm*modinv(i,MOD)
  c %= MOD
print(c)

Submission status: Runtime Error

Solution code:
import math

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

l = a[0]
for i in range(1, n):
    l = l * a[i] // math.gcd(l, a[i])

for i in range(n):
    sum += int(l/a[i]) % mod

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
import math
import fractions

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

l = a[0]
for i in range(1, n):
    l = l * a[i] // math.gcd(l, a[i])

for i in range(n):
    sum += int(l/a[i]) % mod

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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


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

for i in range(n):
    sum += int(l/a[i]) % mod

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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


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


for i in range(n):
    sum += int(l/a[i]) % mod

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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


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


for i in range(n):
    sum += l/a[i] % mod

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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


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


for i in range(n):
    sum += l/a[i] % mod

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
n=int(input())
lcm=1
l=[]
mod=1e9+7
ans=0
l=list(map(int,input().split()))
for x in l:
    lcm=lcm*x // gcd(lcm,x)
for x in l:
    ans = (ans + (lcm//x))%mod
print(int(ans))

Submission status: Runtime Error

Solution code:
import functools
import math

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

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

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

lcm = lcm_list(a)
ans = 0
for i in range(n):
	ans += (lcm // a[i]) % MOD

print(ans % MOD)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

n = int(input())
a = list(map(int,input().split()))
MOD = 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)
ans = 0
for i in range(n):
	ans += (lcm // a[i]) % MOD

print(ans % MOD)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

n = int(input())
a = list(map(int,input().split()))
MOD = 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)
ans = 0
for i in range(n):
	ans += lcm // a[i]

print(ans % MOD)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

lcma = 1
for aa in a:
    lcma = lcma * aa // math.gcd(lcma, aa)

ans = 0
for aa in a:
    ans += lcma // aa
    ans %= 1000000007
print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

lcm = 1
for aa in a:
    lcm = lcm * aa // math.gcd(lcm, aa)

ans = 0
for aa in a:
    ans += lcm // aa
    ans %= 1000000007
print(ans)