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: Time Limit Exceeded

Solution code:
from fractions import gcd

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

g=A[0]
l=A[0]
for i in range(N):
    g=gcd(l,A[i])
    l=l*A[i]//g
    
ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    ans%=mod
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
import fractions 
from functools import reduce
arr = list(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)
    
a = lcm(arr)

ans = 0

for i in arr:
    ans+= a//i
    if ans >1000000007:
        ans % 1000000007
print(ans %(1000000000+7))

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

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

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

g = 0
for x in a:
    g = gcd(g, x)

l = 1
for i in range(n):
    a[i] //= g
    l = lcm(l, a[i])

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

print(ans)

Submission status: Time Limit Exceeded

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

mod = 1000000007

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

A = a[0]
for i in range(1, n):
    g = gcd(A, a[i])
    A = A * (a[i] // g)

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

Submission status: Time Limit Exceeded

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

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


def gcd(x, y):
    if y % x == 0:
        return x

    return gcd(y % x, x)


def lcd(x, y):
    g = gcd(x, y)
    return x * y // g


l = 1
for e in a:
    l = lcd(l, e)

ans = 0
for e in a:
    ans += l // e
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = list(map(int,input().split()))
MOD = 1000000007

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

A.append(1)
a = A[0]
b = A[1]
lcm = a * b // GCD(a,b)
for i in range(2,N):
  a = lcm
  b = A[i]
  lcm = a * b // GCD(a,b)
ans = 0
for i in range(N):
  ans = (ans + (lcm // A[i])) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline
MOD = 10**9+7

n = int(input())
A = list(map(int, input().split()))
lcm = A[0]
for a in A[1:]:
    if lcm % a != 0:
        lcm = lcm*a//gcd(a, lcm)
ans = 0
for a in A:
    ans = (ans+lcm//a)%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

CONST = 10 ** 9 + 7

def lcm(list_):
    return reduce(lambda x, y: x * y // gcd(x, y), list_)

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

l = lcm(a)
total = 0

for a_ in a:
    total += l // a_
    if total >= CONST:
        total %= CONST

print(total)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import sys
input = sys.stdin.readline
def main():
    mod = 10**9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]
    sub = A[0]
    for i in range(1, N):
        sub = (sub * A[i]) // fractions.gcd(sub, A[i])
    ans = 0

    for i in range(N):
        ans += sub//A[i]
        ans %= mod
    print(ans%mod)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

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

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = lcm_list(A)
    ans = 0
    MOD = 10 ** 9 + 7
    for a in A:
        ans += D // a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
n = int(input())
al = list(map(int,input().split()))
al = sorted(al, reverse=True)
p = al[0]
for i in range(1, n):
    p = p * al[i] // fractions.gcd(p, al[i])

ans = 0

for a in al:
    ans += p // a
    ans %= 10**9 + 7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
A = [int(i) for i in input().split()]
k = [lcm_list(A)] * n
r = 0
for i in range(n):
    r += k[i]//A[i]
    if r > 10**9+7:
        r %= 10**9+7
print(r)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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


mod = 10**9+7


N = int(input())

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

g = 1

for i in range(N):
    g = lcm(g,A[i])

ans = 0

for i in range(N):
    ans += g // A[i]
    ans %= mod

print (ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import fractions

from functools import reduce

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

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

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

def LI():
  return [int(s) for s in input().split()]

N = int(input())
A_s = LI()

mod = 10**9 + 7

l = lcm_list(A_s)

print(sum(map(lambda x : l//x, A_s)) % mod)

Submission status: Time Limit Exceeded

Solution code:
# ABC152e


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)
    MOD = 10**9+7

    from fractions import gcd

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

    from functools import reduce

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

    n = int(input())
    a = list(map(int, input().split()))
    o = lcm(*a)
    # print(o)
    b = 0
    for i in a:
        b += o//i % MOD
    print(b % MOD)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd


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

lcm = A[0]

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:


from fractions import gcd
from collections import Counter

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

L = A[0]
for i in range(1, N):
    L = L * A[i] // gcd(L, A[i])

# A を圧縮
c = Counter(A)
values, counts = zip(*c.most_common())

ans = 0
for ci in range(len(values)):
    ans += (L // values[ci]) * counts[ci] % INF
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

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

n = int(input())
aaa = get_nums_l()

g = reduce(lcm, aaa)

ans = 0
for a in aaa:
    ans += g//a
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from sys import stdin
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

if __name__ == "__main__":
    mod = 10**9+7
    N = int(stdin.readline().rstrip())
    A = [int(x) for x in stdin.readline().rstrip().split()]
    ans = 0
    l = reduce(lcm,A)
    for j in A:
        ans += (l//j)
        ans %= mod
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


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

a.sort(reverse=True)
v1, v2 = None, None
L = None

# if len(a) > 1:
#     v1 = a[0]
#     v2 = a[1]
#     L = lcm(v1, v2)
#     # print(L)
# else:
#     L = reduce(lcm, a)

L = reduce(lcm, a)

# print(L)

for i in range(n):
    ans += (L // a[i])
    # ans %= mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

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

index = lcm_list(A)

MOD = 10**9 + 7

ans = 0

for a in A:
    ans += (index//a) % MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
  
B = [(l // i) % MOD for i in A]

ans = sum(B) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
import fractions 
from functools import reduce
arr = list(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)
    
a = lcm(arr)

ans = 0

for i in arr:
    ans+= a//i
    
print(ans %(1000000000+7))

Submission status: Time Limit Exceeded

Solution code:
def gcm(a: int, b: int):
    while b > 0:
        a, b = b, a % b
    return a


def lcm(a: int, b: int):
    return a * b // gcm(a, b)


n = int(input())
a_array = list(map(int, input().split()))
a_lcm = 1
for a in a_array:
    a_lcm = lcm(a_lcm, a)
count = 0
for a in a_array:
    count += (a_lcm // a) % (10 ** 9 + 7)
    count %= 10 ** 9 + 7
print(count)

Submission status: Time Limit Exceeded

Solution code:
import unittest
import functools


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 3, 4]), 13)

    def test_2(self):
        self.assertEqual(think([12, 12, 12, 12, 12]), 5)

    def test_3(self):
        self.assertEqual(think([1000000, 999999, 999998]), 996989508)

    def test_4(self):
        self.assertEqual(gcd(3, 2), 1)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    mode = 10 ** 9 + 7
    lcm_of_all_a = functools.reduce(lambda x, y: lcm(x, y), a, 1)
    b = list(map(lambda x: lcm_of_all_a // x, a))
    return sum(b) % mode


def write(result):
    print(result)


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


def gcd(a, b):
    if a < b:
        return gcd(b, a)

    while True:
        if a % b == 0:
            return b
        a, b = b, a % b


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Time Limit Exceeded

Solution code:
import fractions
def main():
    mod = 10**9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]
    sub = A[0]
    for i in range(1, N):
        sub = (sub * A[i]) // fractions.gcd(sub, A[i])
    ans = 0

    for i in range(N):
        ans += sub//A[i]
        ans %= mod
    print(ans%mod)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from collections import Counter

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

L = A[0]
for i in range(1, N):
    L = L * A[i] // gcd(L, A[i])

# A を圧縮
c = Counter(A)
values, counts = zip(*c.most_common())

ans = 0
for ci in range(len(values)):
    ans += (L // values[ci]) * counts[ci] % INF
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

lcm_ = A[0]
for a in A[1:]:
    lcm_ = lcm_ * a // gcd(lcm_, a)

ans = 0
for a in A:
    ans = (ans + lcm_ // a) % (10 ** 9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
mod = 10**9 + 7
n = int(input())
As = list(map(int, input().split()))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

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

n = int(input())
aaa = get_nums_l()

g = reduce(lcm, aaa)

x = [ g//a for a in aaa]
print(sum(x) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline


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


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

ans = 0
prev = A[0]
for a in A:
    l = lcm(prev, a)
    factor = l // prev % mod
    ans = (ans * factor + l // a) % mod
    prev = l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
mod = 10**9 + 7
n = int(input())
lst = list(map(int, input().split()))

koubai = lcm_list(lst)
total = 0
for l in lst:
    b = koubai//l
    total += b
    total %= mod
print(total)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    lcm = 1
    for a in A:
        lcm =  (lcm * a) // gcd(lcm, a)
    ans = 0

    for a in A:
        ans = (ans + lcm // a) % MOD
    print(ans)

    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: Time Limit Exceeded

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

import fractions
lcm = 1
for ai in a:
    lcm = ai * lcm // fractions.gcd(ai, lcm)

ans = 0
for ai in a:
    ans += (lcm // ai)

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

Submission status: Time Limit Exceeded

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

import fractions

k=A[0]

for i in range(N-1):
  l=fractions.gcd(A[i+1],k)
  k=k*A[i+1]//l
#print(k)
x=0
for i in range(N):
  x+=k//A[i]
  x=x%1000000007
print(x)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

def find_lcm(denominators):
  return reduce(lambda a,b: a*b // gcd(a,b), denominators)

def solve(nums):
  modula = 10**9 + 7
  lcm = find_lcm(nums)

  ans = 0
  for n in nums:
    ans += (lcm // n) % modula

  print(ans % modula)


    
def iin(): return int(input())
def iln(): return list(map(int, input().split()))


N = iin()
nums = iln()
solve(nums)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.sort()
"""a,bの最大公約数"""
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

"""a,bの最小公倍数"""
def lcm(a,b):
    return a*b//gcd(a,b)
m=1
mod=1000000007
for i in range(n):
    m=lcm(m,x[i])
ans=0
for i in range(n):
    ans+=(m//x[i])%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(v) for v in input().split()]

def gcd(v1, v2):
    if v2 == 0:
        return v1
    return gcd(v2, v1 % v2)

a1 = A[0]

for a2 in A[1:]:
    a3 = gcd(a1, a2)
    a1 = a1 * a2 // a3

#print(a1)

v = a1
total = 0
for a in A:
    total += v // a 
    total %= 1000000007
    #while total > 1000000007:
    #total -= 1000000007

print(total)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    if x % y == 0:
        return y
    else:
        return gcd(y, x % y)
def lcm(x, y):
    return x // gcd(x, y) * y

N = int(input())
A = [int(x) for x in input().split()]

X = 1
for i in range(N):
#     X = X * A[i] // math.gcd(X, A[i])
    X = lcm(X, A[i])

MOD = 10 ** 9 + 7
ans = 0
for i in range(N):
    ans = (ans + X // A[i]) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions as 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()))
MOD=(10**9)+7

LCM=lcm_list(A)
ans=0

for i in range(N):
    ans+=(LCM//A[i])
    ans=ans%MOD

print(ans)

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce
def lcm_base(x, y):
    return x // fractions.gcd(x, y) * y
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

MOD = 10 ** 9 + 7
l = lcm(an)
sm = 0
for a in an:
  sm = (sm + l // a) % MOD
print(sm)

Submission status: Time Limit Exceeded

Solution code:
import sys

def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        x, y = y, x % y
    return x

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

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))

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

ans = 0
for i in range(n):
    ans = (ans + c // a[i]) % 1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
n = int(input())
al = list(map(int,input().split()))
al = sorted(al)
p = al[0]
for i in range(1, n):
    p = p * al[i] // fractions.gcd(p, al[i])

ans = 0

for a in al:
    ans += p // a
    ans %= 10**9 + 7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        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]]

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def cnk(a, b):
    MOD = 10**9+7
    ret = 1
    for i in range(b):
        ret *= (a-i)
        ret %= MOD
        ret = ret * modinv(i+1, MOD) % MOD
    return ret




def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    v = a[0]
    for i in range(1, n):
        v = lcm(v, a[i])
    
    ans = 0
    v %= MOD
    for i in range(n):
        ans += v * modinv(a[i], MOD) % MOD
        ans %= MOD
    print(int(ans))
    # n = int(input())
    # d = defaultdict(int)
    # for i in range(1,n+1):
    #     if i < 10:
    #         d[(i, i)] += 1
    #     else:
    #         d[(int(str(i)[-1]), int(str(i)[0]))] += 1
    
    # ans = 0
    # for i in range(1, n):
    #     if i < 10:
    #         ans +=d[(i, i)]
    #     else:
    #         if int(str(i)[-1]) == int(str(i)[0]):
    #             ans += d[(int(str(i)[0]), int(str(i)[-1]))]
    #         else:
    #             ans += d[(int(str(i)[0]), int(str(i)[-1]))]
    # print(ans)

            


    




    


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#E
n=int(input())
a=list(map(int,input().split()))
import fractions
lcm=a[0]
b_sum=0
for i in range(1,n):
    lcm=lcm*a[i]//fractions.gcd(lcm,a[i])

num=10**9+7
for i in range(n):
    b_sum+=(lcm//a[i])%num

print(b_sum%num)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd

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

mod=10**9+7
def lcm(a, b):
    return a*b/gcd(a, b)

lc=1
for a in A:
    lc=lcm(lc,a)

ans=0
for a in A:
    b=lc/a
    ans+=b

print ans%mod

Submission status: Time Limit Exceeded

Solution code:
def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

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

    l = reduce(lcm, A)
    ans = [(l // a) % MOD for a in A]
    return sum(ans) % MOD

print(e_flatten())

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce


MOD = 10 **9 + 7

def lcm_base(x, y):
    return (x * y) // 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()))

tmp = lcm(*A)

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

print (ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
input = sys.stdin.readline
N = int(input())
list_A = list(map(int, input().split()))
ans = list_A[0]
sum = 0
for i in range(1, N):
    ans *= list_A[i] // fractions.gcd(ans, list_A[i])
if ans == list_A[0]:
    print(N%(7+10**9))
else:
    for a in list_A:
        sum += ans//a
    print(sum%(7+10**9))

Submission status: Time Limit Exceeded

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

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

l = a[0]
for x in range(n - 1):
    l = l // gcd(l, a[x + 1]) * a[x + 1]

ans = 0
for x in range(n):
    ans += l // a[x]
    ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#E
n=int(input())
a=list(map(int,input().split()))
import fractions
lcm=a[0]
b_sum=0
for i in range(1,n):
    lcm=lcm*a[i]//fractions.gcd(lcm,a[i])

num=10**9+7
for i in range(n):
    b_sum+=(lcm//a[i])%num

print(b_sum%num)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

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

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

common=lcm_list(A)
ans=0
for i in range(N):
    ans+=common//A[i]
print(ans%a)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
n=int(input())
numbers=list(map(int,input().split()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=[]
for i in range(n):
    l.append(lcm_list(numbers)//numbers[i])
print(sum(l)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
def lcm(a):
  from fractions import gcd
  x = a[0]
  for i in range(1, len(a)):
    x = (x * a[i] // gcd(x, a[i]))
  return x

n = int(input())
a = list(map(int, input().split()))
i = 0
mod = 1000000000 + 7
min = lcm(a)
sum = 0
while i < n:
  sum = sum + (min//a[i]) 
  i = i + 1
  
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

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

num = nums[0]
for i in range(N - 1):
    num = lcm(num, nums[i + 1])
print(sum([num // i for i in nums]) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
def main():
    from fractions import gcd
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=list(map(int,input().split()))
    # n,*a=map(int,open(0).read().split())
    mod=10**9+7
    b=max(a)
    for i in a:
        if b%i!=0:
            b=b*i//gcd(b,i)
    ans=0
    for i in a:
        ans+=b//i
        ans%=mod
    print(ans)    
    # print(sum(b//i%mod for i in a)%mod)    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


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

li = [0] * (10 ** 6 + 1)

for e in a:
    fct = factorization(e)
    for l in fct:
        num, times = l
        li[num] = max(li[num], times)

lcm = 1
for i, e in enumerate(li):
    lcm *= i ** e

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions


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

a=A[0]
for b in A:
    a = a * b / fractions.gcd(a, b)

count=0
for i in A:
    count+=a/i

print(int(count)%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
def e_flatten(MOD=10**9 + 7):
    from fractions import gcd
    from functools import reduce
    N = int(input())
    A = [int(i) for i in input().split()]

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

    l = reduce(lcm, A)
    ans = [l // a for a in A]
    return sum(ans) % MOD

print(e_flatten())

Submission status: Time Limit Exceeded

Solution code:
import fractions
n = int(input())
al = list(map(int,input().split()))

p = al[0]
for i in range(1, n):
    p = p * al[i] // fractions.gcd(p, al[i])

ans = 0

for a in al:
    ans += p // a
    ans %= 10**9 + 7

print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
arr = list(map(int , input().split()))
lcm = arr[0]
for i in range(1,n):
  hcf = gcd(lcm, arr[i])
  lcm = (lcm*arr[i])//hcf
sum =0
for i in range(0,n):
  sum = sum +(lcm//arr[i])
sum =sum%1000000007
print(int(sum))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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

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

l = reduce(lcm, nums)

ans = 0
for i in range(n):
	ans = (ans + l // nums[i]) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

def find_lcm(denominators):
    return reduce(lambda a,b: a*b // gcd(a,b), denominators)

def solve(nums):
    modula = 10**9 + 7
    lcm = find_lcm(nums)

    bs = []
    for n in nums:
        bs.append(lcm // n)

    print(sum(bs) % modula)

    
def iin(): return int(input())
def iln(): return list(map(int, input().split()))


N = iin()
nums = iln()
solve(nums)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

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

n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))

l = 1

for i in a:
  l = lcm(l, i)

s = 0

MOD = 10 ** 9 + 7

for i in a:
    s += l // i
    s %= MOD

print(s)

Submission status: Time Limit Exceeded

Solution code:
def main():

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

    A.sort(reverse = True)
    
    def gcd(a, b):
        if a > b:
            a, b = b, a
        if a == 0: return b
        return gcd(b%a, a)

    b = 1
    for i in range(N):
        if b % A[i] != 0:
            g = gcd(b, A[i])
            b = b * A[i] // g

    ans = 0
    for i in range(N):
        ans += (b // A[i]) % mod
        ans %= mod
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)
n=int(input())
#A=random.sample(list(range(1, 10**6)), k=10**4)
A=[int(i) for i in input().split()]
Z=lcm(A)
ans=0
for a in A:
    ans =(ans+Z//a) % lim
print(ans)