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 sys
import math
input = sys.stdin.readline


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

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

ans = 0
for a in A:
    ans += lcm // a
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
input = sys.stdin.readline


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

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

ans = 0
for a in A:
    ans += lcm // a

print(ans % mod)

Submission status: Runtime Error

Solution code:
import sys
import math
input = sys.stdin.readline


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

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

ans = 0
for a in A:
    ans += lcm // a

print(ans % mod)

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
now = A[0]
ans = 0
for i in range(1,N):
    now = now//math.gcd(now, A[i])*A[i]
for i in range(N):
    ans += now//A[i]
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
import math
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
now = A[0]
ans = 0
for i in range(1,N):
    now = (now*A[i])//math.gcd(now, A[i])
for i in range(N):
    ans += now//A[i]
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if(a==0):
        return b
    return gcd(b%a , a)
MOD = 10**9 + 7
    
n = int(input())
arr = map(int , input().strip().split())
ar = []
lcc = 0
for x in arr:
    ar.append(x)
    if(lcc==0):
        lcc = x
    lcc = (lcc*x)/gcd(lcc,x)
lcc = int(lcc)
res = 0 
for y in ar:
    #print(lcc / y)
    res = res + (lcc/y)
res = res%MOD
print(int(res))

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
mod = 10**9+7

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 = list(map(int, input().split()))

LCM = lcm(a_list)

print(sum(list(map(lambda x: (LCM // x) % mod, a_list))) % mod)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if not b: 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()))
l = 1
ans, mod = 0, 1000000007
for x in A:
    l = lcm(l, x)
for x in A:
    ans = (ans + l/x)
    if ans > mod: ans %= MOD
print(ans)

Submission status: Runtime Error

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

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

A = []

N = int(raw_input())
A = map(int, raw_input().split())
l = 1
for x in A:
    l = lcm(l, x)
ans, mod = 0, 1000000007
for x in A:
    ans = (ans + l/x)
    if ans > mod: ans = ans % mod
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
import sys
from collections import defaultdict
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

d = defaultdict(int)
def factorize2(n): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            d[i] = max(d[i],j)
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        d[n] = max(d[n],1)
    return 0

ans = 0
for i in range(N):
    factorize2(A[i])
K = list([k**d[k] for k in d.keys()])
L = reduce(mul,K)
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
import sys
from collections import defaultdict
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

d = defaultdict(int)
def factorize2(n,d): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            d[i] = max(d[i],j)
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        d[n] = max(d[n],1)
    return table # list

ans = 0
for i in range(N):
    factorize2(A[i],d)
K = list([k**d[k] for k in d.keys()])
L = reduce(mul,K)
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
import sys
from collections import defaultdict

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

d = defaultdict(int)
def factorize2(n,d): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    table = defaultdict(int)
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            d[i] = max(d[i],j)
            table[i] = j
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        d[n] = max(d[n],1)
        table[n] = 1
    return table # list

ans = 0
T = []
for i in range(N):
    T.append(factorize2(A[i],d))
L = reduce(mul,list([k**d[k] for k in d.keys()]))
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
import sys
from collections import defaultdict

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

d = defaultdict(int)
def factorize2(n,d): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    table = defaultdict(int)
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            d[i] = max(d[i],j)
            table[i] = j
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        d[n] = max(d[n],1)
        table[n] = 1
    return table # list
def lcm(a, b): # 最小公倍数
    return a * b // gcd(a, b) # int


ans = 0
T = []
for i in range(N):
    T.append(factorize2(A[i],d))
L = reduce(mul,list([k**d[k] for k in d.keys()]))
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
input = sys.stdin.readline # 文字列の入力のとき'/n'まで受け取るので注意!!!
sys.setrecursionlimit(500000)
from operator import mul

d = defaultdict(int)
def factorize2(n,d): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    table = defaultdict(int)
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            d[i] = max(d[i],j)
            table[i] = j
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        d[n] = max(d[n],1)
        table[n] = 1
    return table # list
def lcm(a, b): # 最小公倍数
    return a * b // gcd(a, b) # int


ans = 0
T = []
for i in range(N):
    T.append(factorize2(A[i],d))
L = reduce(mul,list([k**d[k] for k in d.keys()]))
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from scipy import gcd
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
def lcm(a, b): # 最小公倍数
    return a * b // gcd(a, b) # int

L = reduce(lcm,A)
ans = 0
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
def lcm(a, b): # 最小公倍数
    return a * b // gcd(a, b) # int

L = reduce(lcm,A)
ans = 0
for i in range(N):
    ans += L//A[i]
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

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

n = int(input())
A = list(map(int, intput().split(' ')))
lcm_A = 1
for a in A:
  lcm_A = lcm(lcm_A, a)

B_sum = 0
for a in A:
  B_sum += lcm_A / a
  B_sum %= 100000000 + 7

print(B_sum)

Submission status: Runtime Error

Solution code:
from fraction import gcd
n=int(input())
a=list(map(int,input().split()))
b=1
for i in a:
  b=gcd(b,i)
ans=0
for i in a:
  ans+=(b//i)
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
from math import gcd

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

temp=A[0]
for item in A:
    temp=temp*item//gcd(temp,item)

ans=0
for item in A:
    ans+=temp//item
    ans%=10**9+7
#print(temp)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
import math
import numpy as np
n = int(input())
ai = [int(i) for i in input().split()]

num = 10**6+1

mod = 10**9+7

if n == 1:
    print(1)
    exit()
    
    
# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor


pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime(ai[i])))
com_ab = [0]*(num)

dic = {}
for a in ai:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

kari = 1
for num,count in dic.items():
    kari *= pow(num,count,mod)

kari_old = kari
ans = 0

for i in range(n):
    kari = kari_old
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    #kari = 1
    #for j in range(kosu):
    #    kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    for j in keys:
        kari *= pow(pow(j,pri_li[i][j],mod),mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
DIVISOR = 10**9 + 7

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

max_el = max(A)


def enumerate_prime(n: int) -> (list, list):
    lis_prime = [True] * (n + 1)
    lis_prime[0] = False
    lis_prime[1] = False
    div_prime = [i for i in range(n+1)]

    primes = []
    primes_idx = {}

    cnt = 0
    for i in range(2, n + 1):
        if lis_prime[i]:
            primes.append(i)
            primes_idx[i] = cnt
            cnt += 1

            j = 2 * i
            while True:
                if j > n:
                    break
                lis_prime[j] = False
                div_prime[j] = i
                j += i

    return primes, primes_idx, div_prime


def iterated_power(z: int, n: int, mod=None) -> int:
    beta = bin(n)[2:]

    Z, q, t = z, 0, len(beta)
    while beta[t - q - 1] == '0':
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        q += 1
    result = Z

    for k in range(q + 1, t):
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        if beta[t - k - 1] == '1':
            result = result * Z
            if mod is not None:
                result = result % mod

    if mod is not None:
        result = result % mod

    return result


primes, primes_idx, div_prime = enumerate_prime(max_el)
# print(primes, primes_idx, div_prime)


max_prime = [0] * len(primes)
res = [[0] * len(primes) for i in range(N)]

for i, a in enumerate(A):
    next_idx = a
    while True:
        div = div_prime[next_idx]
        res[i][primes_idx[div]] += 1
        max_prime[primes_idx[div]] = max(res[i][primes_idx[div]], max_prime[primes_idx[div]])
        if next_idx == div:
            break
        next_idx = int(next_idx / div)

# print(res)
# print(max_prime)

ans = 0
for i, a in enumerate(A):
    temp = 1
    for j, prime in enumerate(primes):
        val = max_prime[j] - res[i][j]
        if val > 0:
            temp *= iterated_power(prime, val, DIVISOR)
    ans += temp % DIVISOR


print(ans % DIVISOR)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# E
# Biは、Aの最小公倍数/Aiで求まるが計算量が間に合わなくなる
# Aiについて素因数分解を効率的に実施する
import sys

DIVISOR = 10**9 + 7

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

max_el = max(A)


def enumerate_prime(n: int) -> (list, list):
    lis_prime = [True] * (n + 1)
    lis_prime[0] = False
    lis_prime[1] = False
    div_prime = [i for i in range(n+1)]

    primes = []
    for i in range(2, n + 1):
        if lis_prime[i]:
            primes.append(i)
            j = 2 * i
            while True:
                if j > n:
                    break
                lis_prime[j] = False
                div_prime[j] = i
                j += i

    return primes, div_prime


def iterated_power(z: int, n: int, mod=None) -> int:
    beta = bin(n)[2:]

    Z, q, t = z, 0, len(beta)
    while beta[t - q - 1] == '0':
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        q += 1
    result = Z

    for k in range(q + 1, t):
        Z = Z * Z
        if mod is not None:
            Z = Z % mod
        if beta[t - k - 1] == '1':
            result = result * Z
            if mod is not None:
                result = result % mod

    if mod is not None:
        result = result % mod

    return result


primes, div_prime = enumerate_prime(max_el)
# print(primes, div_prime)
# sys.exit()

# print(primes)

'''
res = [[0]*len(primes) for i in range(N)]
for i, a in enumerate(A):
    for j, prime in enumerate(primes):
        while True:
            if a % prime == 0:
                a = int(a / prime)
                res[i][j] += 1
            if a % prime != 0:
                break
        max_prime[j] = max(res[i][j], max_prime[j])
'''

max_prime = [0] * (max_el+1)
res = [[0] * (max_el+1) for i in range(N)]

for i, a in enumerate(A):
    next_idx = a
    while True:
        div = div_prime[next_idx]
        res[i][div] += 1
        max_prime[div] = max(res[i][div], max_prime[div])
        if next_idx == div:
            break
        next_idx = int(next_idx / div)

# print(res)
# print(max_prime)

ans = 0
for i, a in enumerate(A):
    temp = 1
    for j, prime in enumerate(primes):
        val = max_prime[prime] - res[i][prime]
        if val > 0:
            temp *= iterated_power(prime, val, DIVISOR)
    ans += temp % DIVISOR


print(ans % DIVISOR)

Submission status: Runtime Error

Solution code:
import fractions
import numpy as np
mod=10**9+7
def lcm(a,b):
  s=fractions.gcd(a,b)
  return a*b//s

n=int(input())
a=list(map(int,input().split()))
l=a[0]
for i in a:
  l=lcm(l,i)
ans=0
a=np.array(a)
ans=int(sum(l/a%mod)%mod)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import numpy as np
mod=10**9+7
def lcm(a,b):
  s=fractions.gcd(a,b)
  return a*b//s

n=int(input())
a=list(map(int,input().split()))
l=a[0]
for i in a:
    l=lcm(l,i)
a=np.array(a)
print(int(sum(l/a%mod)%mod))

Submission status: Runtime Error

Solution code:
n = int(input())
ai = [int(i) for i in input().split()]

num = 10**6+1

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

sosu_li = [[i,0] for i in range(num)]
kosu = 0

for i in range(n):
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        #print(sosu_li)
        if sosu_li[j][1] == 0:
            sosu_li[j][1] = 1
            kosu += 1
        com_ab[j] = max(com_ab[j],pri_li[i][j])

sosu_li.sort(reverse=True,key=lambda x: x[1])
"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

kari = 1

for j in range(kosu):
    kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)

kari_old = kari

for i in range(n):
    kari = kari_old
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    #kari = 1
    #for j in range(kosu):
    #    kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    for j in keys:
        kari *= pow(pow(j,pri_li[i][j],mod),mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**3

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

sosu_li = [[i,0] for i in range(10**6+1)]

kosu = 0

for i in range(n):
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        #print(sosu_li)
        if sosu_li[j][1] == 0:
            sosu_li[j][1] = 1
            kosu += 1
        com_ab[j] = max(com_ab[j],pri_li[i][j])

sosu_li.sort(reverse=True,key=lambda x: x[1])
exit()
"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(kosu):
        kari *= pow(sosu_li[j][0],com_ab_new[sosu_li[j][0]],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:

import fractions
from functools import reduce

DIVISOR = 10**9 + 7

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


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


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

res = lcm(*A)
# print(res)

ans = 0
for i in range(N):
    ans += int(res / A[i]) % DIVISOR

print(int(ans) % DIVISOR)

Submission status: Runtime Error

Solution code:

import math
from functools import reduce

DIVISOR = 10**9 + 7

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


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


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

res = lcm(*A)
# print(res)

ans = 0
for i in range(N):
    ans += int(res / A[i]) % DIVISOR

print(int(ans) % DIVISOR)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**3

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

sosu_li = [[i,0] for i in range(10**6+1)]

kosu = 0

for i in range(n):
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        #print(sosu_li)
        if sosu_li[j][1] == 0:
            sosu_li[j][1] = 1
            kosu += 1
        com_ab[j] = max(com_ab[j],pri_li[i][j])

sosu_li.sort(reverse=True,key=lambda x: x[1])

"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(kosu):
        kari *= pow(sosu_li[j][0],com_ab_new[sosu_li[j][0]],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**5

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

for i in range(n):
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        com_ab[j] = max(com_ab[j],pri_li[i][j])

"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(num):
        if com_ab_new[j] > 0:
            kari *= pow(j,com_ab_new[j],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**4

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

for i in range(n):
    tmp = 1
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        com_ab[j] = max(com_ab[j],pri_li[i][j])

"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0
exit()
for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(num):
        if com_ab_new[j] > 0:
            kari *= pow(j,com_ab_new[j],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**3+100

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

for i in range(n):
    tmp = 1
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        com_ab[j] = max(com_ab[j],pri_li[i][j])

"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    tmp = [0]*(num)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(num):
        if com_ab_new[j] > 0:
            kari *= pow(j,com_ab_new[j],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**3

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

for i in range(n):
    tmp = 1
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        com_ab[j] = max(com_ab[j],pri_li[i][j])

"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    tmp = [0]*(num)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(num):
        if com_ab_new[j] > 0:
            kari *= pow(j,com_ab_new[j],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(10**3)

for i in range(n):
    tmp = 1
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        com_ab[j] = max(com_ab[j],pri_li[i][j])

com_num = 1

for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)

ans = 0

for i in range(n):
    ans += com_num // ai[i]
    ans %= mod
print(ans)
exit()
    
pri_li0 = copy.copy(pri_li[0])

for i in range(n-1):
    pri_li[0] += pri_li[i+1]

b_li = [pri_li[0]-pri_li0]

for i in range(1,n):
    b_li.append(pri_li[0]-pri_li[i])

com = copy.copy(b_li[0])
#print(com)
for i in range(1,n):
    com &= b_li[i]
#print(com)
#exit()
for i in range(n):
    b_li[i] -= com

ans = 0
for i in range(n):
    tmp = 1
    #print(len(b_li[i]))
    keys = b_li[i].keys()
    #print(keys)
    for j in keys:
        #print(b_li[i][j])
        #exit()
        tmp *= pow(j, b_li[i][j],mod)
        tmp %= mod
    ans += tmp
    ans %= mod

print(ans%mod)

Submission status: Runtime Error

Solution code:
import fractions

n = int(input())
ai = [int(i) for i in input().split()]


mod = 10**9+7

if n == 1:
    print(1)
    exit()

b_li = []

seki = 1

for i in range(n):
    seki *= ai[i]
    seki %= mod

for i in range(n):
    b_li.append(seki/ai[i])

t_gcd = fractions.gcd(b_li[0],b_li[1])

for i in range(n-2):
    t_gcd = int(fractions.gcd(t_gcd,b_li[i+2]))
    
ans = 0

for i in range(n):
    ans += int(seki/t_gcd/ai[i])
    
print(ans%mod)

Submission status: Runtime Error

Solution code:
import fractions

n = int(input())
ai = [int(i) for i in input().split()]


mod = 10**9+7

if n == 1:
    print(1)
    exit()

b_li = []

seki = 1

for i in range(n):
    seki *= ai[i]

for i in range(n):
    b_li.append(seki/ai[i])

t_gcd = fractions.gcd(b_li[0],b_li[1])

for i in range(n-2):
    t_gcd = int(fractions.gcd(t_gcd,b_li[i+2]))
    
ans = 0

for i in range(n):
    ans += int(seki/t_gcd/ai[i])
    
print(ans%mod)

Submission status: Runtime Error

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

lcm = 1
from math import gcd
for i in range(n):
    lcm *= a[i] // gcd(a[i], lcm)

ans = 0
for i in a:
    ans += lcm // i

print(ans % (10**9+7))

Submission status: Runtime Error

Solution code:
import sys


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

    return gcd(b, a % b)


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


def lcm_n(nums):
    if len(nums) == 1:
        return nums[0]

    lcms = []
    for i in range(1, len(nums)):
        lcms.append(lcm(nums[i-1], nums[i]))

    return lcm_n(lcms)


def main():
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

    target = lcm_n(a)

    for i in a:
        ans += int(target / i)

    print(ans % (10**9 + 7))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys


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

    return gcd(b, a % b)


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


def lcm_n(nums):
    if len(nums) == 1:
        return nums[0]

    lcms = []
    for i in range(1, len(nums)):
        lcms.append(lcm(nums[i-1], nums[i]))

    return lcm_n(lcms)


def main():
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

    target = lcm_n(a)

    for i in a:
        ans += int(target / i)

    print(ans)


if __name__ == '__main__':
    main()