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) .

Solution (Python):
import fractions
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
p=10**9+7
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm(*numbers):
    return reduce(lcm_base,numbers,1)
num=lcm(*a)
l=0
for i in range(n):
  l+=num*pow(a[i],p-2,p)
print(l%p)

Solution (Python):
import sys
import math

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()


def inverse(x, mod):
    return pow(x, mod - 2, mod)


def factorize(x):
    count = {}
    i = 2
    while i * i <= x:
        while x % i == 0:
            x //= i
            count[i] = count.get(i, 0) + 1
        i += 1
    if x > 1:
        count[x] = count.get(x, 0) + 1
    return count


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

A = list(map(factorize, A))

lcm = {}
for i in A:
    for factor, count in i.items():
        lcm[factor] = max(lcm.get(factor, 0), count)

MOD = 1000000007

lcm_int = 1
for factor, count in lcm.items():
    lcm_int *= pow(factor, count, MOD)
    lcm_int %= MOD

ans = 0
for i in A:
    B = lcm_int
    for factor, count in i.items():
        B *= inverse(pow(factor, count, MOD), MOD)
        B % MOD
    ans = (ans + B) % MOD
print(ans)

Solution (Python):
def read_values():
    return map(int, input().split())
 
 
def read_list():
    return list(read_values())

def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = read_list()
  
    u = {}
    for a in A:
      m = 2
      while m * m <= a:
        c = 0
        while a % m == 0:
          c += 1
          a //= m
        if c > 0:
          u[m] = max(u.get(m, 0), c)
        m += 1
      if a > 1:
        u[a] = max(u.get(a, 0), 1)

    lcm = 1
    for k, v in u.items():
      lcm *= pow(k, v, mod)
      lcm %= mod

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

    print(ans)

if __name__ == "__main__":
  main()

Solution (Python):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def g(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = read_list()

    B = 1
    for a in A:
        B *= a // g(B, a)
    
    print(sum(B // a for a in A) % mod)


if __name__ == "__main__":
    main()

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

def lcm(a,b):
    return (a*b)//gcd(a,b)
n = int(input())
mod = int(1e9 + 7)
a = [int(i) for i in input().split()]
ans = int(1)
for i in a:
    ans = lcm(ans,i)

print(sum(ans//i for i in a)%mod)

Solution (Python):
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
n=int(input())
mod=1000000007
s=[int(i) for i in input().split()]
ans=1
for i in s:
    ans*=i//gcd(ans,i)
print(sum(ans//i for i in s)%mod)

Solution (Python):
import fractions
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
def comb(n,k,mod):
    c = 1
    for i in range(k):
        c = c*(n-i)%mod
        c = c*mod_inv(i+1,mod)%mod
    return c
n = int(input())
a = list(map(int,input().split()))
g = a[0]
ans = 1
mod = 10**9 + 7
for i in range(1,n):
    p = fractions.gcd(g,a[i])
    g1 = (a[i]//p)*g
    ans *= (g1//g)
    ans %= mod
    ans += g1//a[i]
    ans %= mod
    g = g1
print(ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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 = I()
a = LI()
lst = [0]*(10**6+1)
for i in a:
    l = factorization(i)
    for (j,k) in l:
        lst[j] = max(lst[j],k)

t = 1
for i in range(1,10**6+1):
    if lst[i] != 0:
        t = t*(i**lst[i]) % mod
ans = 0
for i in a:
    ans += t*pow(i,mod-2,mod) % mod
    ans %= mod
print(ans)

Solution (Python):
MOD = 10**9 + 7
MAX_NUM = 10**3
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(MAX_NUM):
    if is_prime[i]:
        primes.append(i)
        for j in range(2*i, MAX_NUM, i):
            is_prime[j] = False

def prime_factorization(x):
    res = {}
    for prime in primes:
        while x % prime == 0:
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
            x //= prime
    if x > 1:
        res[x] = 1
    return res

def mod_pow(p, q):
    res = 1
    while q:
        if q & 1:
            res = (res * p) % MOD
        p = (p * p) % MOD
        q //= 2
    return res

def mod_inv(p):
    return mod_pow(p, MOD - 2)

def solve(n, a):
    D = {}
    for i in range(n):
        prime_num_mapping = prime_factorization(a[i])
        for prime, num in prime_num_mapping.items():
            if not prime in D:
                D[prime] = 0
            D[prime] = max(D[prime], num)
    L = 1
    for prime, num in D.items():
        L = (L * mod_pow(prime, num)) % MOD
    res = sum(L * mod_inv(x) for x in a)
    return res % MOD

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

Solution (Python):
def main():
    from fractions import gcd
    import sys
    input=sys.stdin.readline
    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=ans+(lcm//a)
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

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

tg = 1
for a in A:
    tg = lcm(tg, a)
ans = 0
for a in A:
    ans += tg // a
print(ans%(10**9+7))

Solution (Python):

from fractions import gcd
from functools import reduce
 
n = int(input())
a = [int(x) for x in input().split()]
 
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
 
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
lcm = lcm_list(a)
ans = 0
for i in range(len(a)):
    ans += lcm // a[i]
print(ans % 1000000007)

Solution (Python):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
l = 1
for x in a:
    l = l * x // gcd(l, x)
ans = 0
for x in a:
    ans += l // x
print(ans % (10 ** 9 + 7))

Solution (Python):
import itertools
import sys
import math
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def get_lcm(num):
    return reduce(lambda x,y:(x * y) // fractions.gcd(x, y), num, 1)

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

    lcm = get_lcm(A)
    sum = 0
    for a in A:
      sum += lcm // a
    _, ans = divmod(sum, (10**9+7))

    print(ans)

if __name__ == "__main__":
  main()

Solution (Python):



def main():
    from fractions import gcd

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

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

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from fractions import gcd

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

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

    for ai in a:
        ans += lcm // ai

    print(ans % mod)


if __name__ == '__main__':
    main()

Solution (Python):
import copy
n=int(input())
a=list(map(int,input().split()))
b=copy.copy(a)
mod=10**9+7
lcm=[0]*max(a)
for i in range(n):
	for j in range(2,int(a[i]**0.5)+1):
		cnt=0
		while a[i]%j==0:
			a[i]//=j
			cnt+=1
		lcm[j-1]=max(lcm[j-1],cnt)
	if a[i]!=1:
		lcm[a[i]-1]=max(lcm[a[i]-1],1)
an=1
for i in range(len(lcm)):
	an*=pow(i+1,lcm[i],mod)
	an%=mod
ans=0
for i in range(n):
	ans+=an*pow(b[i],mod-2,mod)
	ans%=mod
print(ans)

Solution (Python):
from collections import Counter

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

primes = [
  2,  3,  5,  7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
 71, 73, 79, 83, 89, 97,101,103,107,109,113,127,131,137,139,149,151,157,163,
167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,
271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,
389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,
503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,
631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,
757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,
883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,
1009
]

def prime_factorize(n):
    res = []
    i = 0
    while primes[i] * primes[i] <= n:
        if n % primes[i] == 0:
            res.append(primes[i])
            n //= primes[i]
        else:
            i += 1
    if n != 1:
        res.append(n)
    return res


lcm_factors = Counter()
for ai in a:
    prime_factors = prime_factorize(ai)
    counter = Counter(prime_factors)
    for k, v in counter.items():
        if k in lcm_factors:
            lcm_factors[k] = max(lcm_factors[k], v)
        else:
            lcm_factors[k] = v

lcm = 1
for k, v in lcm_factors.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD

ans = 0
for ai in a:
    ans += lcm * pow(ai, MOD - 2, MOD)
    ans %= MOD

print(ans)

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

mod = 10 ** 9 + 7

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

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

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

l %= mod
B = 0
for i in range(len(A)):
    B += l * pow(A[i], mod - 2, mod)
    B %= mod

print(B)

Solution (Python):
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
l=a[0]
for i in range(1,n):
  l=lcm(l,a[i])
ans=0
l%=mod
for i in range(n):
  ans+=l*pow(a[i],mod-2,mod)
  ans%=mod
print(ans)

Solution (Python):
def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
def lcm(a,b): 
    return (a*b) // gcd(a,b) 
  
n = int(input())
arr = input()   
a = list(map(int,arr.split(' ')))
l = a[0]
ans = 0
for i in range(n):
    l = lcm(l, a[i])
for i in range(n):
    ans = ans + l//a[i]
print(ans%1000000007)

Solution (Python):
import collections

def divs(n):
  dic={}
  if n==2:
    dic={}
    dic[2]=1
    return dic
  elif n==3:
    dic={}
    dic[3]=1
    return dic
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      dic[i]=1
      n=n//i
      while n%i==0:
        dic[i]+=1
        n=n//i
  if n!=1:
    dic[n]=1
  return dic        

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
l=collections.defaultdict(int)
ans=0
for i in range(n):
  ans+=pow(arr[i],mod-2,mod)
  ans%=mod
  d=divs(arr[i])
  for keys in d.keys():
    l[keys]=max(l[keys],d[keys])
for keys in l.keys():
  ans*=pow(keys,l[keys],mod)
  ans%=mod
print(ans)

Solution (Python):


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

modulus = 10 ** 9 + 7
binmod = (bin(modulus - 2))[2:]  

MAX = 10 ** 6

def factorize(x):
    vec = {}
    d = 2
    while d * d <= x:
        if x % d == 0:
            if d not in vec:
                vec[d] = 0
            vec[d] += 1
            x //= d
        else:
            d += 1
    if x > 1:
        if x not in vec:
            vec[x] = 0
        vec[x] += 1
    return vec

def value(x):
    p = 1
    for i in x:
        p = (p * (i ** x[i])) % modulus
    return p

def inverse(x):
    p = 1
    for b in binmod:
        p = p * p % modulus
        if b == '1':
            p = p * x % modulus
    return p

def div(n, d):
    return n * inverse(d) % modulus

l = {}
for x in a:
    f = factorize(x)
    for k in f:
        l[k] = max(l[k], f[k]) if k in l else f[k]
lcm = value(l)

s = sum(div(lcm, x) for x in a) % modulus
print(s)

Solution (Python):


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

modulus = 10 ** 9 + 7
binmod = (bin(modulus - 2))[2:]  

MAX = 10 ** 6

primefact = [0 for i in range(MAX + 1)]

def sieve():
    
    for i in range(2, MAX + 1):
        if primefact[i] == 0:
            for j in range(i, MAX + 1, i):
                if primefact[j] == 0:
                    primefact[j] = i

def factorize(x):
    if primefact[2] == 0:
        sieve()

    vec = {}
    while x >= 2:
        d = primefact[x]
        if d not in vec:
            vec[d] = 0
        vec[d] += 1
        x //= d
    return vec

def value(x):
    p = 1
    for i in x:
        p = (p * (i ** x[i])) % modulus
    return p

def inverse(x):
    p = 1
    for b in binmod:
        p = p * p % modulus
        if b == '1':
            p = p * x % modulus
    return p

def div(n, d):
    return n * inverse(d) % modulus

l = {}
for x in a:
    f = factorize(x)
    for k in f:
        l[k] = max(l[k], f[k]) if k in l else f[k]
lcm = value(l)

s = sum(div(lcm, x) for x in a) % modulus
print(s)

Solution (Python):


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

modulus = 10 ** 9 + 7
binmod = (bin(modulus - 2))[2:]  

MAX = 10 ** 6

primefact = [0 for i in range(MAX + 1)]

def sieve():
    
    for i in range(2, MAX + 1):
        if primefact[i] == 0:
            for j in range(i, MAX + 1, i):
                if primefact[j] == 0:
                    primefact[j] = i

def factorize(x):
    if primefact[2] == 0:
        sieve()

    vec = {}
    while x >= 2:
        d = primefact[x]
        if d not in vec:
            vec[d] = 0
        vec[d] += 1
        x //= d
    return vec

def value(x):
    p = 1
    for i in x:
        p = (p * (i ** x[i])) % modulus
    return p

def inverse(x):
    p = 1
    for b in binmod:
        p = p * p % modulus
        if b == '1':
            p = p * x % modulus
    return p

def div(n, d):
    return n * inverse(d) % modulus

fact = [factorize(x) for x in a]

fset = set()
for f in fact:
    fset.update(f.keys())

l = {k: 0 for k in fset}
for f in fact:
    for k in f:
        l[k] = max(l[k], f[k])
lcm = value(l)

s = sum(div(lcm, x) for x in a) % modulus
print(s)

Solution (Python):

def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
def lcm(a,b): 
    return (a*b) // gcd(a,b) 
  
n = int(input())
arr=input()
a=list(map(int,arr.split(' ')))
l = a[0]
ans = 0
for i in range(n):
    l = lcm(l, a[i])
for i in range(n):
    ans = ans + l//a[i]
print(ans%1000000007)

Solution (Python):
from fractions import gcd
from functools import reduce, partial
import sys


def input():
    return sys.stdin.readline()[:-1]

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

def func(a, b, l):
	mod = 10**9 + 7
	return (a +  l*modinv(b, mod)) % mod

def modinv(a, b):
	return pow(a,b-2,b)

def main():
	mod = 10**9 + 7
	N = int(input())
	A = tuple(map(int, input().split()))

	l = reduce(lcm, A) % mod
	A = (0,) + A
	
	ans = reduce(partial(func, l=l), A)
	print(ans)
	

if __name__ == "__main__":
	main()

Solution (Python):

from fractions import gcd
N = input()
A = list(map(int, input().split(" ")))
def lcm(x, y):
    return (x * y) // gcd(x, y)
tmp = 1
for i in A:
    tmp = lcm(tmp, i)
print(sum([tmp // i for i in A]) % (10**9 + 7))

Solution (Python):
from fractions import gcd


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

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

ans = 0
for a in A:
    ans += lcm * pow(a, MOD - 2, MOD) % MOD
    ans %= MOD

print(ans)

Solution (Python):
from fractions import gcd


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


def mod_inv(a, m):
    return pow(a, m-2, m)


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

LCM = 1
for a in A:
    LCM = lcm(LCM, a)
LCM %= MOD

ans = 0
for a in A:
    ans += LCM * mod_inv(a, MOD) % MOD
    ans %= MOD

print(ans)

Solution (Python):
from fractions import gcd


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


def mod_inv(a, m):
    return pow(a, m-2, m)


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

LCM = 1
for a in A:
    LCM = lcm(LCM, a)
LCM %= MOD


ans = 0

for a in A:
    ans += LCM * mod_inv(a, MOD) % MOD
    ans %= MOD

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

from fractions import gcd


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


def mod_inv(a, m):
    return pow(a, m-2, m)


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

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


ans = 0
for a in A:
    ans += LCM * mod_inv(a, MOD) % MOD
    ans %= MOD

print(ans)

Solution (Python):
from fractions import gcd


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


def mod_inv(a, m):
    return pow(a, m-2, m)


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

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


ans = 0
for a in A:
    ans += LCM * mod_inv(a, MOD) % MOD
    ans %= MOD

print(ans)

Solution (Python):
from fractions import gcd


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


def mod_inv(a, m):
    return pow(a, m-2, m)


MOD = 10 ** 9 + 7

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


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

ans = _lcm * sum([mod_inv(s, MOD) for s in A]) % MOD

print(int(ans % MOD))

Solution (Python):
from fractions import gcd


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


MOD = 10 ** 9 + 7

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


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

ans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD

print(int(ans % MOD))

Solution (Python):
from fractions import gcd


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



MOD = 10 ** 9 + 7

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


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

ans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD

print(int(ans % MOD))

Solution (Python):
from fractions import gcd

mod = 10 ** 9 + 7

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

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

ans = lcm * sum([pow(s, mod - 2, mod) for s in A]) % mod

print(int(ans % mod))

Solution (Python):
from fractions import gcd

import numpy as np
import sys
input = sys.stdin.readline
mod = 10**9+7

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

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

ans = lcm*sum([pow(s, mod-2, mod) for s in A]) % mod


print(int(ans%mod))

Solution (Python):
def main():
  def sieve(n):
    prime=[]
    limit=n*0.5
    data=[i+1 for i in range(1,n)]
    p_append=prime.append
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        p_append(p)
        data=[e for e in data if e%p!=0]
        
  prime=sieve(1000)
  import sys
  import numpy as np
  input=sys.stdin.readline
  mod=10**9+7
  
  n=int(input())
  num=list(map(int,input().split()))
  num_copy=np.array(num)
  
  lcm=1
  for p in prime:
    while np.any(num_copy%p==0):
      num_copy[num_copy%p==0]//=p
      lcm *= p
      lcm %= mod
  
  for i in set(num_copy.tolist()):
    lcm *= i
    lcm %= mod
    
  
  ans=0
  for i in range(n):
    ans += lcm * pow(num[i] ,mod-2 ,mod)
    ans %= mod 
    
  print(ans)
  
if  __name__=='__main__':
  main()

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

def main():
	n, *a = map(int, open(0).read().split())
	mod = 10 ** 9 + 7
	lcm = 1
	for x in a:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= mod
	ans = sum(pow(x, mod - 2, mod) for x in a) % mod
	print(ans * lcm % mod)

if __name__ == "__main__":
	main()

Solution (Python):
from functools import reduce

def solve():
    MOD = 10**9 + 7

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

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

    lcmA = reduce(lcm, As)
    

    ans = 0
    for A in As:
        ans += lcmA // A
    ans %= MOD

    print(ans)

solve()

Solution (Python):


n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
from functools import reduce
def lcm(x,y):
  return (x*y)//gcd(x,y)
mod = 10**9+7
l = reduce(lcm, a) % mod
ans = 0
for i in range(n):
  ans += l * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)

Solution (Python):
from collections import Counter

def solve():
    MOD = 10**9 + 7
    maxA = 10**6

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

    def getMinPFs(n):
        isPrimes = [False]*2 + [True]*(n-1)
        minPFs = [1] + list(range(1, n+1))
        for d in range(2, int(n**0.5)+1):
            if isPrimes[d]:
                minPFs[d] = d
                for x in range(d*d, n+1, d):
                    isPrimes[x] = False
                    if minPFs[x] == x:
                        minPFs[x] = d
        return minPFs

    minPFs = getMinPFs(maxA)

    def getPrimeFactors(x, minPFs):
        anss = []
        while minPFs[x] > 1:
            anss.append(minPFs[x])
            x //= minPFs[x]
        return anss

    cntP = Counter()
    for A in As:
        PFs = getPrimeFactors(A, minPFs)
        for key, num in Counter(PFs).items():
            cntP[key] = max(cntP[key], num)

    lcmA = 1
    for key, num in cntP.items():
        lcmA *= pow(key, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(maxA, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()

Solution (Python):
from collections import Counter

def solve():
    MOD = 10**9 + 7
    maxA = 10**6

    def getPrimeFactors(x):
        anss = []
        while x%2 == 0:
            anss.append(2)
            x //= 2
        for d in range(3, int(x**0.5)+1, 2):
            while x%d == 0:
                anss.append(d)
                x //= d
        if x != 1:
            anss.append(x)
        return anss

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

    cntP = Counter()
    for A in As:
        PFs = getPrimeFactors(A)
        for key, num in Counter(PFs).items():
            cntP[key] = max(cntP[key], num)

    lcmA = 1
    for key, num in cntP.items():
        lcmA *= pow(key, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(maxA, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()

Solution (Python):
import sys
input = sys.stdin.buffer.readline

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

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

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

print(ans%mod)

Solution (Python):
MOD = 10**9+7
class mint:
    def __init__(self, x):
        self.x = x % MOD if isinstance(x, int) else int(x) % MOD
    def __str__(self):
        return str(self.x)
    __repr__ = __str__
    def __iadd__(self, other):
        self.x += other.x if isinstance(other, mint) else other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __isub__(self, other):
        self.x += MOD-other.x if isinstance(other, mint) else MOD-other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __imul__(self, other):
        self.x *= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __imod__(self, other):
        self.x %= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __add__(self, other):
        return (
            mint(self.x + other.x) if isinstance(other, mint) else
            mint(self.x + other)
        )
    def __sub__(self, other):
        return (
            mint(self.x - other.x) if isinstance(other, mint) else
            mint(self.x - other)
        )
    def __mul__(self, other):
        return (
            mint(self.x * other.x) if isinstance(other, mint) else
            mint(self.x * other)
        )
    def __mod__(self, other):
        return (
            mint(self.x % other.x) if isinstance(other, mint) else
            mint(self.x % other)
        )
    def __truediv__(self, other):
        return (
            mint(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(self.x * pow(other, MOD - 2, MOD))
        )
    def __pow__(self, other):
        return (
            mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
            mint(pow(self.x, other, MOD))
        )
    __radd__ = __add__
    def __rsub__(self, other):
        return (
            mint(other.x - self.x) if isinstance(other, mint) else
            mint(other - self.x)
        )
    __rmul__ = __mul__
    def __rmod__(self, other):
        return (
            mint(other.x % self.x) if isinstance(other, mint) else
            mint(other % self.x)
        )
    def __rtruediv__(self, other):
        return (
            mint(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(other * pow(self.x, MOD - 2, MOD))
        )
    def __rpow__(self, other):
        return (
            mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
            mint(pow(other, self.x, MOD))
        )

class Sieve:
    
    def __init__(self, n):
        f = [0]*(n+1)
        primes = list()
        f[0] = f[1] = -1
        for i in range(2,n+1):
            if f[i]:
                continue
            primes.append(i)
            f[i]=i
            for j in range(i*i, n+1, i):
                if not f[j]:
                    f[j] = i
        self.f = f
        self.primes = primes
    def isPrime(self, x):
        return self.f[x] == x
    def factorList(self, x):
        res = list()
        while x > 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res
    def factor(self, x):
        fl = self.factorList(x)
        if len(fl) == 0:
            return list()
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res

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

l = dict()

sv = Sieve(1000005)

for i in range(n):
    f = sv.factor(a[i])
    for p in f:
        try:
            l[p[0]] = max(l[p[0]], p[1])
        except:
            l[p[0]] = p[1]

lcm = mint(1)

for f,s in l.items():
    lcm *= f**s

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i])
ans = 0
for i in range(n):
  ans += l // a[i]
print(ans%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
from functools import reduce
def lcm(x,y):
  return (x*y)//gcd(x,y)
mod = 10**9+7
l = reduce(lcm, a) % mod
ans = 0
for i in range(n):
  ans += l * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)

Solution (Python):
import sys
from fractions import gcd

input = sys.stdin.buffer.readline

LARGE = 10 ** 9 + 7

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

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

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

total = 0
for a in A:
    total += l // a

print(total % LARGE)

Solution (Python):
import sys
import fractions
input = sys.stdin.buffer.readline
def lcm(x,y):
  return((x*y)//fractions.gcd(x,y))
def main():
  N=int(input())
  arr=list(map(int,input().split()))
  MOD=1000000007 
  LCM=1
  for i in arr:
    LCM=lcm(LCM,i)
  ans=0
  for i in arr:
    ans += LCM//i
  print(ans%MOD)
if __name__=="__main__":
  main()

Solution (Python):
from collections import Counter

def solve():
    MOD = 10**9 + 7

    def getPrimeFactors(x):
        anss = []
        for d in range(2, int(x**0.5)+1):
            while x%d == 0:
                anss.append(d)
                x //= d
        if x != 1:
            anss.append(x)
        return anss

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

    PFss = []
    Primes = set()
    for A in As:
        PFs = getPrimeFactors(A)
        cnt = Counter(PFs)
        PFss.append(cnt)
        Primes |= cnt.keys()

    cntP = Counter()
    for PFs in PFss:
        for key, num in PFs.items():
            cntP[key] = max(cntP[key], num)

    lcmA = 1
    for key, num in cntP.items():
        lcmA *= pow(key, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(10**6, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()

Solution (Python):
import sys
input = sys.stdin.buffer.readline
import fractions
from functools import reduce

def main():
    N = int(input())
    a = list(map(int,input().split()))
    MOD = 10**9+7
            
    def lcm(x,y):
        return((x*y)//fractions.gcd(x,y))
        
    l = reduce(lcm,a)
    ans = 0
    for num in a:
        ans += l//num
    
    print(ans%MOD)

if __name__ == "__main__":
    main()