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:
n=int(input())
a=list(map(int,input().split()))
import functools
import fractions 
mod=pow(10,9)+7
# 最小公倍数
def lcm(x, y):
  return ((x * y) // fractions.gcd(x, y))
def lcmn(nums):
  return functools.reduce(lcm, nums)
lcma=lcmn(a)
ans=0
for ai in a:
  ans+=lcma//ai
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
import functools
import fractions 
# 最小公倍数
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)
def lcmn(nums):
  return functools.reduce(lcm, nums)
lcma=lcmn(a)
ans=0
mod=pow(10,9)+7
for ai in a:
  ans+=lcma//ai
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    g = gcd(A[0],A[1])
    lcm = (A[0]*A[1]) // g
    for x in A[2:]:
        lcm = (lcm * x) // gcd(lcm,x)
    print(sum((lcm//x) for x in A)%1000000007)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    g = gcd(A[0],A[1])
    lcm = (A[0]*A[1]) // g
    for x in A[2:]:
        if max(lcm,x) % min(lcm,x) == 0:
            g = min(lcm,x)
        else:
            g = gcd(lcm,x)
        lcm = (lcm * x) // g
    ans = 0
    for x in A:
        ans = (ans + (lcm // x)) % 1000000007
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from functools import reduce
from operator import mul

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)
    b = Counter(a)
    return b
def modmul(a,b):
    return a * b % 1000000007
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    fac = prime_factorize(A[0]) | prime_factorize(A[1])
    for x in A[2:]:
        fac |= prime_factorize(x)
    ans = 0
    f = [pow(x[0],x[1],1000000007) for x in fac.items()]
    if len(f) > 0:
        lcm = reduce(modmul,f)
    else:
        lcm = 1
    for x in A:
        ans = (ans + (lcm * modinv(x,1000000007))) % 1000000007
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

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

arr = []
for i in a:
    ar = factorization(i)
    arr.append(ar)
    for j,k in ar:
        if j not in d:
            d[j] = k
        else:
            d[j] = max(k, d[j])

for i in arr:
    d2 = copy.copy(d)
    tmp = 1
    for j,k in i:
        d2[j] -= k
    for k,v in d2.items():
        tmp *= pow(k,v,mod)
    ans += tmp
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from functools import reduce
from operator import mul

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)
    b = Counter(a)
    return b

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    fac = prime_factorize(A[0]) | prime_factorize(A[1])
    for x in A[2:]:
        fac |= prime_factorize(x)
    ans = 0
    f = [pow(x[0],x[1],1000000007) for x in fac.items()]
    if len(f) > 0:
        lcm = reduce(mul,f)
    else:
        lcm = 1
    for x in A:
        ans = (ans + (lcm // x)) % 1000000007
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    gcd = xgcd(A[0],A[1])
    lcm = (A[0]*A[1]) // gcd
    for x in A[2:]:
        if max(lcm,x) % min(lcm,x) == 0:
            gcd = min(lcm,x)
        else:
            gcd = xgcd(lcm,x)
        lcm = (lcm * x) // gcd
    ans = 0
    for x in A:
        ans = (ans + (lcm // x)) % 1000000007
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    gcd = xgcd(A[0],A[1])
    lcm = (A[0]*A[1]) // gcd
    for x in A[2:]:
        if max(lcm,x) % min(lcm,x) == 0:
            gcd = min(lcm,x)
        else:
            gcd = xgcd(lcm,x)
        lcm = (lcm * x) // gcd
    ans = 0
    b = [lcm // x for x in A]
    for x in b:
        ans = (ans + x) % 1000000007
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    gcd = xgcd(A[0],A[1])
    lcm = (A[0]*A[1]) // gcd
    for i in range(2,N):
        gcd = xgcd(lcm,A[i])
        lcm = (lcm * A[i]) // gcd
    ans = 0
    b = [lcm // x for x in A]
    for x in b:
        ans = (ans + x) % 1000000007
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    gcd = xgcd(A[0],A[1])
    lcm = (A[0] * A[1]) // gcd
    for i in range(2,N):
        gcd = xgcd(lcm,A[i])
        lcm = (lcm * A[i]) // gcd
    print(sum([lcm // x for x in A])%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import sys

def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for j in range(4, n+1, 2):
        is_prime[j] = False
    for i in range(3, int(n**0.5) + 1, 2):
        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 main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    n = int(input())
    a = [int(x) for x in input().split()]
    
    prime_list = prime(max(a))
    len_list = len(prime_list)
    L_prime = [0]*len_list
    for i in range(n):
        judge = a[i]
        for j in range(len_list):
            count = 0
            while not judge%prime_list[j]:
                count += 1
                judge //= prime_list[j]
            if count > L_prime[j]:
                L_prime[j] = count
    
    L = 1
    for i in range(len_list):
        L *= pow(prime_list[i], L_prime[i], mod)
        L %= mod
    
    ans = 0
    for i in range(n):
        ans += (L*pow(a[i], mod-2, mod))%mod
        ans %= mod
    
    print(ans)
            


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def prime(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for j in range(4, n+1, 2):
        is_prime[j] = False
    for i in range(3, int(n**0.5) + 1, 2):
        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 main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    n = int(input())
    a = [int(x) for x in input().split()]
    
    prime_list = prime(max(a))
    len_list = len(prime_list)
    L_prime = [0]*len_list
    for i in range(n):
        judge = a[i]
        for j in range(len_list):
            count = 0
            while not judge%prime_list[j]:
                count += 1
                judge //= prime_list[j]
            if count > L_prime[j]:
                L_prime[j] = count
    ans = 0
    for i in range(n):
        key = 1
        judge = a[i]
        for j in range(len(prime_list)):
            count = 0
            while not judge%prime_list[j]:
                count += 1
                judge //= prime_list[j]
            key *= pow(prime_list[j], L_prime[j]-count, mod)
            key %= mod
        ans += key
        ans %= mod
    
    print(ans)
            


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def factorize(n: int) -> dict:
    f = defaultdict(int)
    while n % 2 == 0:
        f[2] += 1
        n //= 2
    p = 3
    while p * p <= n:
        while n % p == 0:
            f[p] += 1
            n //= p
        p += 2
    if n != 1:
        f[n] += 1
    return f


def _pow(b, p, mod):
    ret = 1
    while p:
        if p % 2 == 1:
            ret *= b
            ret %= mod
        b **= 2
        p //= 2
    return ret


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

a_fac = []
lcm_fac = defaultdict(int)
for a_i in a:
    a_fac_i = factorize(a_i)
    a_fac.append(a_fac_i)
    for k, v in a_fac_i.items():
        lcm_fac[k] = max(lcm_fac[k], v)

# print(lcm_fac)
ans = 0
for a_fac_i in a_fac:
    b_i = 1
    for k, v in lcm_fac.items():
        b_i *= _pow(k, v - a_fac_i[k], MOD)
        b_i %= MOD
    # print(i, a[i], b_i)
    ans += b_i
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def factorize(n: int) -> dict:
    f = defaultdict(int)
    while n % 2 == 0:
        f[2] += 1
        n //= 2
    p = 3
    while p * p <= n:
        while n % p == 0:
            f[p] += 1
            n //= p
        p += 2
    if n != 1:
        f[n] += 1
    return f


def _pow(b, p, mod):
    ret = 1
    while p:
        if p % 2 == 1:
            ret *= b
            ret %= mod
        b **= 2
        p //= 2
    return ret


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

a_fac = []
lcm_fac = defaultdict(int)
for i in range(n):
    a_fac.append(factorize(a[i]))
    for k, v in a_fac[i].items():
        lcm_fac[k] = max(lcm_fac[k], v)

# print(lcm_fac)
ans = 0
for a_fac_i in a_fac:
    b_i = 1
    for k, v in lcm_fac.items():
        b_i *= _pow(k, v - a_fac_i[k], MOD)
        b_i %= MOD
    # print(i, a[i], b_i)
    ans += b_i
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def factorize(n: int) -> dict:
    f = defaultdict(int)
    while n % 2 == 0:
        f[2] += 1
        n //= 2
    p = 3
    while p * p <= n:
        while n % p == 0:
            f[p] += 1
            n //= p
        p += 2
    if n != 1:
        f[n] += 1
    return f


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

a_fac = []
lcm_fac = defaultdict(int)
for i in range(n):
    a_fac.append(factorize(a[i]))
    for k, v in a_fac[i].items():
        lcm_fac[k] = max(lcm_fac[k], v)

# print(lcm_fac)
ans = 0
for a_fac_i in a_fac:
    b_i = 1
    for k, v in lcm_fac.items():
        b_i *= pow(k, v - a_fac_i[k], MOD)
        b_i %= MOD
    # print(i, a[i], b_i)
    ans += b_i
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

cnt=0
ans=0
LCM=1
for i in range(n):
    Q=lcm(LCM,A[i])
    cnt*=Q//LCM
    LCM=Q
    cnt+=Q//A[i]
print(cnt%mod)

Submission status: Time Limit Exceeded

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


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X*Y//y


l = 1

mod = pow(10, 9) + 7


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

ans = 0

for i in list(a):
    ans += l // i
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions as f

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

l = 1

mod = pow(10, 9) + 7

for i in list(a):
    l = l * i // f.gcd(l, i)

ans = 0

for i in list(a):
    ans += l // i
    ans %= mod
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
MOD=10**9+7
def euclid(a, b):
  if b == 0:
    return a
  else:
    return euclid(b, a%b)

def multiple(a, b):
  return a*b // euclid(a, b)

def lcm(nums):
  return functools.reduce(multiple, nums)
n=int(input())
a=list(map(int,input().split()))
x=lcm(a)
sum=0
for i in range(n):
    sum+=x//a[i]
print(sum%MOD)

Submission status: Time Limit Exceeded

Solution code:
import collections as col

def prime(n):
    ans = []
    num = n
    for i in range(2, int(n**0.5)+1):
        while not num%i: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return col.Counter(ans)
    
n = int(input())
a = list(map(int,input().split()))

cnt = col.Counter()
for num in a:
    new = prime(num)
    for key,val in new.items():
        if val > cnt[key] : cnt[key] = val

LCM = 1
MOD = 10**9 + 7
for key,val in cnt.items(): LCM *= key**val

ans = 0
for num in a:
    b = LCM//num
    ans += b%MOD
    
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections as col

def prime(n):
    ans = []
    num = n
    for i in range(2, int(n**0.5)+1):
        while not num%i: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return col.Counter(ans)
    
n = int(input())
a = list(map(int,input().split()))

cnt = col.Counter()
for num in a:
    new = prime(num)
    for key,val in new.items():
        if val > cnt[key] : cnt[key] = val

LCM = 1
MOD = 10**9 + 7
for key,val in cnt.items(): LCM *= key**val

ans = 0
for num in a:
    b = LCM//num
    ans += b%MOD
    
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
P = 10**9+7
N = int(input())
S = list(map(int, input().split()))

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

ans = 0
for i in range(N):
    ans = (temp//S[i]+ans)%P
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

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


ans = 0
for a in A:
    # フェルマーの小定理
    ans += lcm * pow(a, MOD-2, MOD)
    ans %= MOD


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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

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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

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

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

def multiple(a, b):
    return a*b // euclid(a, b)

def lcm(nums):
        return functools.reduce(multiple, nums)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import fractions
from functools import reduce
mod = 10**9+7

def gcd(*numbers):
    return reduce(fractions.gcd,numbers)
def lcm_bace(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm(*numbers):
    return reduce(lcm_bace,numbers,1)

ans = 0
for i in A:
    ans += (lcm(*A)//i)%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import fractions
from functools import reduce
mod = 10**9+7

def gcd(numbers):
    return reduce(fractions.gcd,numbers)
def lcm_bace(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm(numbers):
    return reduce(lcm_bace,numbers,1)

A_lcm = lcm(A)
ans = 0
for i in A:
    ans += (A_lcm//i)%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import fractions
from functools import reduce
mod = 10**9+7

def gcd(*numbers):
    return reduce(fractions.gcd,numbers)
def lcm_bace(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm(*numbers):
    return reduce(lcm_bace,numbers,1)

A_lcm = lcm(*A)
ans = 0
for i in A:
    ans += (A_lcm//i)%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


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


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

  
x = reduce(lcm, A)
print(sum(x//a % MOD for a in A) % MOD)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


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


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


x = reduce(lcm, A)

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


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


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


x = reduce(lcm, A)

ans = 0
for a in A:
    ans += x//a % MOD
    # ans %= MOD
print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


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


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


x = reduce(lcm, A)

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
mod = 10 ** 9 + 7


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


def LCM(a, b, mod=10 ** 9 + 7):
    res = a * pow(GCD(a, b), mod - 2, mod)
    res %= mod
    res *= b
    res %= mod
    return res


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


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A_lcm = list(accumulate(A, func=lcm))[-1]

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

Submission status: Time Limit Exceeded

Solution code:

from fractions import gcd

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

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

ans = 0
for a in A:
  ans += x//a
  ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

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

ans = 0
for a in A:
  ans += x//a
  ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

def multiple(a, b):
    return a*b // fractions.gcd(a, b)
def lcm(nums):
  return functools.reduce(multiple, nums)

def main():
  N = int(input())
  A = list(map(int, input().split()))
  B = set(A[:])
  n = lcm(B)
  ans = 0
  mod = 10**9+7
  for a in A:
    ans += n//a
    ans %= mod

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

def multiple(a, b):
    return a*b // fractions.gcd(a, b)
def lcm(nums):
  return functools.reduce(multiple, nums)

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

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

def multiple(a, b):
    return a*b // fractions.gcd(a, b)
def lcm(nums):
  return functools.reduce(multiple, nums)

N = int(input())
A = list(map(int, input().split()))
n = lcm(A)
ans = 0
mod = 10**9+7
for a in A:
  ans += n//a
  ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

def lcm(l):
  x = l[0]
  for i in range(1, len(l)):
    x = (x * l[i]) // fractions.gcd(x, l[i])
  return x  

N = int(input())
A = list(map(int, input().split()))
n = lcm(A)
ans = 0
mod = 10**9+7
for a in A:
  ans += n//a
  ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1,2):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = [f(A[i]) for i in range(N)]

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(B[i+1].keys()) + list(lp.keys()):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1,2):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = [f(A[i]) for i in range(N)]

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1,2):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = []
for i in range(N):
    B.append(f(A[i]))

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = []
for i in range(N):
    B.append(f(A[i]))

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = []
for i in range(N):
    B.append(f(A[i]))

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
    
l = 1
B = 0

for i in range(N):
  l = lcm(l,A[i])
for i in range(N):
  B += l//A[i]%mod
B %= mod

print(B)

Submission status: Time Limit Exceeded

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

A = sorted(A)
mod = 10**9+7
setA = [0]*N
setA[-1] = A[-1]

for i in range(N):
  if A[-1]%A[i] != 0:
    setA[i] = A[i]
setA = [s for s in setA if s != 0]


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)
 
 
l = lcm(*setA)
B = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
mod = 10**9+7
setA = []
for i in range(N):
  if A[-1]%A[i] != 0 or i == N-1:
    setA.append(A[i])

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)
 
 
l = lcm(*setA)
B = 0
for i in range(N):
  B += l//A[i]%mod
B %= mod
print(B)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
setA = list(set(A))
mod = 10**9+7
 
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)
 
 
l = lcm(*setA)
B = 0
for i in range(N):
  B += l//A[i]%mod
B %= mod
print(B)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

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)


l = lcm(*A)
B = 0
for i in range(N):
  B += l//A[i]%mod
B %= mod
print(B)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

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)


l = lcm(*A)
B = 0
for i in range(N):
  B += l//A[i]
  B %= mod
print(B)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    for i in range(2,int(sqrt(n))+1):
        if n % i == 0:
            r = 0
            while n % i == 0:
                n //= i
                r += 1
            d[i] = r
    if n != 1:
        d[n] = 1
    return d

B = []
for i in range(N):
    B.append(f(A[i]))

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)