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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]


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


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

Submission status: Time Limit Exceeded

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


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


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

Submission status: Time Limit Exceeded

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


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


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

Submission status: Time Limit Exceeded

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


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


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    end = len(ll) - 1
    for j in range(len(aa)):
        if len(ll) == 0:
            ll.append(aa[j])
        else:
            left = 0
            rght = end
            while left < rght:
                cntr = (rght + left) // 2
                if ll[cntr][0] == aa[j][0]:
                    left = cntr
                    rght = cntr
                elif ll[cntr][0] > aa[j][0]:
                    rght = cntr - 1
                elif ll[cntr][0] < aa[j][0]:
                    left = cntr + 1
            if left <= end and ll[left][0] == aa[j][0]:
                ll[left][1] = max(ll[left][1], aa[j][1])
            else:
                ll.append(aa[j])
    ll.sort(key=lambda x: x[0])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        if len(ll) == 0:
            ll.append(aa[j])
        else:
            left = 0
            rght = len(ll) - 1
            while left < rght:
                cntr = (rght + left) // 2
                if ll[cntr][0] == aa[j][0]:
                    left = cntr
                    rght = cntr
                elif ll[cntr][0] > aa[j][0]:
                    rght = cntr - 1
                elif ll[cntr][0] < aa[j][0]:
                    left = cntr + 1
            if ll[left][0] == aa[j][0]:
                ll[left][1] = max(ll[left][1], aa[j][1])
            else:
                ll.append(aa[j])
            ll.sort(key=lambda x: x[0])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        if len(ll) == 0:
            ll.append(aa[j])
            ll.sort(key=lambda x: x[0])
        else:
            left = 0
            rght = len(ll) - 1
            if ll[left][0] == aa[j][0]:
                rght = left
            elif ll[rght][0] == aa[j][0]:
                left = rght
            while left < rght:
                cntr = (rght + left) // 2
                if ll[cntr][0] == aa[j][0]:
                    left = cntr
                    rght = cntr
                elif ll[cntr][0] > aa[j][0]:
                    rght = cntr - 1
                elif ll[cntr][0] < aa[j][0]:
                    left = cntr + 1
            if ll[left][0] == aa[j][0]:
                ll[left][1] = max(ll[left][1], aa[j][1])
            else:
                ll.append(aa[j])
                ll.sort(key=lambda x: x[0])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        if len(ll) == 0:
            ll.append(aa[j])
            ll.sort(key=lambda x: x[0])
        else:
            left = 0
            rght = len(ll) - 1
            while left < rght:
                cntr = (rght + left) // 2
                if ll[cntr][0] == aa[j][0]:
                    left = cntr
                    rght = cntr
                elif ll[cntr][0] > aa[j][0]:
                    rght = cntr - 1
                elif ll[cntr][0] < aa[j][0]:
                    left = cntr + 1
            if ll[left][0] == aa[j][0]:
                ll[left][1] = max(ll[left][1], aa[j][1])
            else:
                ll.append(aa[j])
                ll.sort(key=lambda x: x[0])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        if len(ll) == 0:
            ll.append(aa[j])
            ll.sort(key=lambda x: x[0])
        left = 0
        rght = len(ll) - 1
        while left < rght:
            cntr = (rght + left) // 2
            if ll[cntr][0] == aa[j][0]:
                left = cntr
                rght = cntr
            elif ll[cntr][0] > aa[j][0]:
                rght = cntr - 1
            elif ll[cntr][0] < aa[j][0]:
                left = cntr + 1
        if ll[left][0] == aa[j][0]:
            ll[left][1] = max(ll[left][1], aa[j][1])
        else:
            ll.append(aa[j])
            ll.sort(key=lambda x: x[0])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        flag = True
        for k in range(len(ll)):
            if aa[j][0] == ll[k][0]:
                ll[k][1] = max(ll[k][1], aa[j][1])
                flag = False
                break
        if flag:
            ll.append(aa[j])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


NN = 10 ** 6 + 100
primes = []
isprime = [True for _ in range(NN + 1)]
min_factor = [-1 for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    min_factor[i] = i
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False
        if min_factor[j] == -1:
            min_factor[j] = i

def prime_factrize(n):
    res = []
    while n != 1:
        prime = min_factor[n]
        exp = 0
        while min_factor[n] == prime:
            exp += 1
            n //= prime
        res.append([prime, exp])
    return res

n = INT()
a = LIST()

ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        flag = True
        for k in range(len(ll)):
            if aa[j][0] == ll[k][0]:
                ll[k][1] = max(ll[k][1], aa[j][1])
                flag = False
        if flag:
            ll.append(aa[j])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

def prime_factorize(n):
    a = []
    a.append(1)
    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 = [[],[]]
    cnt = 1
    for i in range(len(a)+1):
        if i > 0 and i < len(a):
            if a[i] == a[i-1]:
                cnt += 1
            else:
                b[0].append(a[i-1])
                b[1].append(cnt)
                cnt = 1
        if i == len(a) and i > 0:
            b[0].append(a[i-1])
            b[1].append(cnt)
        elif i == len(a) and i == 0:
            b[0].append(a[i])
            b[1].append(cnt)
    return b

n = INT()
a = LIST()
ll = [[], []]
aa = []
for i in range(n):
    aa.append(prime_factorize(a[i]))
    for j in range(len(aa[i][0])):
        if aa[i][0][j] in ll[0]:
            idx = ll[0].index(aa[i][0][j])
            ll[1][idx] += max(0, aa[i][1][j] - ll[1][idx])
        else:
            ll[0].append(aa[i][0][j])
            ll[1].append(aa[i][1][j])
ans = 0
l = 1
for i in range(n):
    b = 1
    for j in range(len(ll[0])):
        if ll[0][j] in aa[i][0]:
            idx = aa[i][0].index(ll[0][j])
            tmp1 = ll[1][j] - aa[i][1][idx]
            b *= ll[0][j] ** tmp1
        else:
            b *= ll[0][j] ** ll[1][j]
    ans += b
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 10**9+7

M = 10**3
primes = []
is_prime = [True] * (M+1)
for n in range(2,M+1):
    if not is_prime[n]: continue
    primes.append(n)
    for m in range(2*n,M+1,n): is_prime[m] + False

from collections import defaultdict
D = [defaultdict(int) for _ in range(N)]
cmnd = defaultdict(int)

for i,a in enumerate(A):
    for n in primes:
        while a % n == 0:
            D[i][n] += 1
            a //= n
    if a > 1: D[i][a] += 1
    for k,v in D[i].items():
        cmnd[k] = max(cmnd[k], v)

ans = 0
for i in range(N):
    tmp = 1
    for k,v in cmnd.items():
        tmp *= (k**(v-D[i][k]))%MOD
        tmp %= MOD
    ans += tmp
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

M = 10**3
primes = []
is_prime = [True] * (M+1)
for n in range(2,M+1):
    if not is_prime[n]: continue
    primes.append(n)
    for m in range(2*n,M+1,n): is_prime[m] + False

from collections import defaultdict
D = [defaultdict(int) for _ in range(N)]
cmnd = defaultdict(int)

for i,a in enumerate(A):
    for n in primes:
        while a % n == 0:
            D[i][n] += 1
            a //= n
    if a > 1: D[i][a] += 1
    for k,v in D[i].items():
        cmnd[k] = max(cmnd[k], v)

ans = Mint()
for i in range(N):
    tmp = Mint(1)
    for k,v in cmnd.items():
        tmp *= k**(v-D[i][k])
    ans += tmp

print(ans)

Submission status: Time Limit Exceeded

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


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


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

MOD = 1000000007
l = A[0]
for i in A[1:]:
    l = lcm(l, i)

ans = 0
for x in A:
    ans += l // x

print(ans % MOD)

Submission status: Time Limit Exceeded

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

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

from collections import defaultdict
D = [defaultdict(int) for _ in range(N)]
cmnd = defaultdict(int)

for i,a in enumerate(A):
    for n in range(2, int(a**0.5)+1):
        while a % n == 0:
            D[i][n] += 1
            a //= n
    if a > 1: D[i][a] += 1
    for k,v in D[i].items():
        cmnd[k] = max(cmnd[k], v)

ans = Mint()
for i in range(N):
    tmp = Mint(1)
    for k,v in cmnd.items():
        tmp *= k**(v-D[i][k])
    ans += tmp

print(ans)

Submission status: Time Limit Exceeded

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

n = INT()
a = LIST()
l = 1
for i in range(n):
    l = lcm(l, a[i])
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
l = 1
for i in range(n):
    l = lcm(l, a[i])
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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


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

MOD = 1000000007
l = A[0]
for i in A[1:]:
    l = lcm(l, i)

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

print(ans)

Submission status: Time Limit Exceeded

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


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


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

MOD = 1000000007
l = A[0]
for i in A[1:]:
    l = lcm(l, i)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd


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


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

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

MOD = 1000000007

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd


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


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

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

MOD = 1000000007

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

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import functools
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    M = 10**9+7
    culcm = functools.reduce(lcm,a)

    b = [culcm//a_i for a_i in a]

    print(sum(b)%M)

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n=int(input())
l=list(map(int,input().split()))
ans=1
t=l[0]
mod=10**9+7
def lcm(n,m):
    return n*m//gcd(n,m)
for i in l[1:]:
    k=lcm(i,t)
    ans*=k//t
    ans%=mod
    ans+=k//i
    t=k
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=1
t=l[0]
mod=10**9+7
def gcd(n,m):
    n,m=sorted([n,m])
    while(m%n!=0):
        n,m=m%n,n
    return n
def lcm(n,m):
    return n*m//gcd(n,m)
for i in l[1:]:
    k=lcm(i,t)
    ans*=k//t
    ans%=mod
    ans+=k//i
    t=k
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=1
t=l[0]
mod=10**9+7
def gcd(n,m):
    n,m=sorted([n,m])
    while(m%n!=0):
        n,m=m%n,n
    return n
def lcm(n,m):
    return n*m//gcd(n,m)
for i in l[1:]:
    ans*=lcm(i,t)//t
    ans%=mod
    ans+=lcm(i,t)//i
    t=lcm(i,t)
print(ans%mod)