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):
MOD = 10**9 + 7


class modint():
    def __init__(self, value):
        self.value = value % MOD

    def __int__(self):
        return int(self.value)

    def __float__(self):
        return float(self.value)

    def __str__(self):
        return str(self.value)

    def __repr__(self):
        return str(self.value)

    def __add__(self, other):
        return (modint(self.value + other.value) if isinstance(other, modint)
                else modint(self.value + other))

    def __sub__(self, other):
        return (modint(self.value - other.value) if isinstance(other, modint)
                else modint(self.value - other))

    def __mul__(self, other):
        return (modint(self.value * other.value) if isinstance(other, modint)
                else modint(self.value * other))

    def __truediv__(self, other):
        return (modint(self.value * pow(other.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(self.value * pow(other, MOD - 2, MOD)))

    def __pow__(self, other):
        return (modint(pow(self.value, other.value, MOD))
                if isinstance(other, modint)
                else modint(pow(self.value, other, MOD)))

    def __eq__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __ne__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __radd__(self, other):
        return (modint(other.value + self.value) if isinstance(other, modint)
                else modint(other + self.value))

    def __rsub__(self, other):
        return (modint(other.value - self.value) if isinstance(other, modint)
                else modint(other - self.value))

    def __rmul__(self, other):
        return (modint(other.value * self.value) if isinstance(other, modint)
                else modint(other * self.value))

    def __rtruediv__(self, other):
        return (modint(other.value * pow(self.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(other * pow(self.value, MOD - 2, MOD)))

    def __rpow__(self, other):
        return (modint(pow(other.value, self.value, MOD))
                if isinstance(other, modint)
                else modint(pow(other, self.value, MOD)))

    def modinv(self):
        return modint(pow(self.value, MOD - 2, MOD))


def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    A = [int(i) for i in input().split()]

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

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

    num = 1
    for a in A:
        num = lcm(num, a)
    n = modint(num)

    ans = 0
    for i, a in enumerate(A):
        ans += n/a
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd

def main():

    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)

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

    print(total % MOD)


if __name__ == "__main__":
    main()

Solution (Python):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

l = 1
for a in A:
    l = a*l//(gcd(a,l))
ans = 0
for a in A:
    ans += l//a
print(ans%MOD)

Solution (Python):
def gcd(a,b):
  while b: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()))
ans=0
mod=10**9+7
l=a[0]
for i in range(1,n):l=lcm(l,a[i])
for i in a:
  ans+=l*pow(i,mod-2,mod)%mod
  ans%=mod
print(ans)

Solution (Python):
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_list(numbers):
  return reduce(lcm_base, numbers, 1)

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

Solution (Python):
import sys
mod = 7 + 10 ** 9

def lcm(a, b):
    a, b = max(a, b), min(a, b)
    c = a * b
    while a % b > 0:
        a, b = b, a % b
    return c // b

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    L = A[0]
    for i in range(1, N): L = lcm(L, A[i])
    L %= mod
    ans = 0
    for a in A:
        ans += (L * pow(a, mod - 2, mod)) % mod
        ans %= mod
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

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

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

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

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, readline().split()))

    def factorization(n):
        factors = []

        while n % 2 == 0:
            factors.append(2)
            n //= 2

        for i in range(3, int(n ** 0.5) + 5, 2):
            while n % i == 0:
                factors.append(i)
                n //= i
        if n != 1:
            factors.append(n)

        return Counter(factors)

    a_fac = [0] * n

    for i, num in enumerate(a):
        a_fac[i] = factorization(num)

    lcm = {1: 1}

    for fac in a_fac:
        for key, value in fac.items():
            lcm[key] = max(lcm.get(key, 0), value)

    ans = 0

    lcmmod = 1

    for key, value in lcm.items():
        lcmmod *= pow(key, value, MOD)
        lcmmod %= MOD

    for ele in a:
        ainv = pow(ele, MOD - 2, MOD)
        ans += ((lcmmod*ainv) % MOD)
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd

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

inverse = [1] * (max_a + 1)
for i in range(2, max_a + 1):
  inverse[i] = -inverse[mod % i] * (mod // i) % mod

lcm = 1
for i in range(n):
  lcm = lcm * a[i] // gcd(lcm, a[i])
lcm %= mod

sum_b = 0
for i in range(n):
  sum_b = (sum_b + lcm * inverse[a[i]]) % mod
print(sum_b)

Solution (Python):
from fractions import gcd

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

lcm = 1
for i in range(n):
  lcm = lcm * a[i] // gcd(lcm, a[i])
lcm %= mod

sum_b = 0
for i in range(n):
  sum_b = (sum_b + lcm * pow(a[i], mod - 2, mod)) % mod
print(sum_b)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().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)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
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

lcd = dict()
for i in num:
  j = dict(factorization(i))
  for x,y in j.items():
    if not x in lcd.keys():
      lcd[x] = y
    else:
      lcd[x] = max(lcd[x],y)

lc = 1
for i,j in lcd.items():
  lc *= pow(i,j,mod)
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

ans =0
for i in range(n):
  ans += lc*modinv(num[i],mod)
  ans %= mod
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
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

lcd = dict()
for i in num:
  j = factorization(i)
  for x in j:
    if not x[0] in lcd.keys():
      lcd[x[0]] = x[1]
    else:
      lcd[x[0]] = max(lcd[x[0]],x[1])

lc = 1
for i,j in lcd.items():
  lc *= pow(i,j,mod)
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

ans =0
for i in range(n):
  ans += lc*modinv(num[i],mod)
  ans %= mod
print(ans)

Solution (Python):
def gcd(a,b):
    if a>b:
        return gcd(b,a)
    if a==0:
        return b
    return gcd(b-a*(b//a),a)
def lcm(x,y):
    return (x*y)//gcd(x,y)
N=int(input())
A=list(map(int,input().split()))
s=1
for a in A:
    s=lcm(s,a)
ans=0
for a in A:
    ans+=s//a
print(ans%(10**9+7))

Solution (Python):
n = int(input())
nums = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def gcd(x, y): 
    
    if x < y:
        x, y = y, x
    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)

LCM = 1
for num in nums:
    LCM = lcm(num, LCM)
LCM %= mod




ans = 0
for num in nums:
    ans += LCM * pow(num, mod - 2, mod)
    ans %= mod

print(ans % mod)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7

import fractions
lc = num[0]
for i in range(1, n):
    lc = lc * num[i] // fractions.gcd(lc, num[i])

lc %= mod    
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

ans =0
for i in range(n):
  ans += lc*modinv(num[i],mod)
  ans %= mod
print(ans)

Solution (Python):
from collections import deque, Counter, defaultdict
from functools import lru_cache
from itertools import permutations
from heapq import (
    heappush,
    heappop,
    heapreplace,
    heappushpop,
    heapify,
    merge,
    nlargest,
    nsmallest,
)
from statistics import mean, median, mode


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


n = int(input())
a = list(map(int, input().split(" ")))
alcm = a[0]
for i in a:
    alcm = lcm(alcm, i)

tot = 0
for num in a:
    tot += alcm // num

print(tot % 1000000007)

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


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


n = int(input())
a = list(map(int, input().split(" ")))
alcm = a[0]
for i in a:
    alcm = lcm(alcm, i)

tot = 0
for num in a:
    tot += alcm // num

print(tot % 1000000007)

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

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

n = int(input())
av = list(map(int, input().split(' ')))
alcm = 1
for i in av:
  alcm = lcm(alcm, i)

tot = 0
for i in range(n):
  tot += alcm // av[i]

print(tot % 1000000007)

Solution (Python):
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
new=[0]*N
A.sort()
insuu=[0]*(A[N-1]+1)
pf={}
l=[]
ans=1
cnt=0
p=(10**9)+7

for i in range(N):
    m = A[i]
    for j in range(2,int(m**0.5)+1):
        while m%j==0:
            pf[j]=pf.get(j,0)+1
            m//=j
    if m>1:pf[m]=1
    
    keys=list(pf.keys())
    values=list(pf.values())
    pf={}
    for j in range(len(keys)):
        if insuu[keys[j]]<values[j]:
            insuu[keys[j]]=values[j]
        
    
for i in range(1,A[N-1]+1,1):
    if insuu[i]>0:
        ans=ans*pow(i,insuu[i])

for i in range(N):
    
    cnt=(cnt+(ans*modinv(A[i],p))%p)%p
print(cnt%p)

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

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

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

L = 1

for a in A:
	L = lcm(L, a)

print(sum(L // a for a in A) % (10 ** 9 + 7))

Solution (Python):
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
lcm = 1
answer = 0
for a in A:
    coef =  a // gcd(lcm, a)
    answer *= coef
    lcm *= coef
    answer += lcm // a

print(answer%MOD)

Solution (Python):
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
lcm = 1
answer = 0
for a in A:
    coef =  a // gcd(lcm, a)
    answer *= coef
    lcm *= coef
    answer += lcm // a

print(answer%MOD)

Solution (Python):
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()

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

print(answer%MOD)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

def make_primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

def prime_decomposition(n): 
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

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

    
    return divisors

def Topo_sort(x,y):
    co = cl.Counter(n for m in x.values() for n in m)
    S = cl.deque([i for i in range(y) if co[i] == 0])
    while S:
        n = S.popleft()
        yield n
        for i in x[n]:
            co[i] -= 1
            if co[i] <= 0:
                S.append(i)
    """
    if sum(co.values()) != 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
    """
    


import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

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

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

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

n = onem()

a = l()

po = max(a)

ans = 0

al = 1

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

al %= mod

for i in range(n):
    ans += al * pow(a[i],mod-2,mod)
    ans %= mod
print(ans)

Solution (Python):
from fractions import gcd
def gyakugen( a, m ):
  b = m
  x, y = 1, 0
  while b>0:
    q = a // b
    a, b = b, a-q*b
    x, y = y, x-q*y
  return x if x>0 else x+m

m=10**9+7
n=int(input())
a=list(map(int,input().split()))
l=a[0]
for i in range(1,n):
  g=gcd(a[i],l)
  l=(a[i]//g)*l
b=0
for i in range(n):
  b=(b+gyakugen(a[i],m))%m
print((b*(l%m))%m)

Solution (Python):
import fractions

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

x=int(input())
a=list(map(int, input().split()))
ans=0
if x==1:
	print(1)
else:
	chk=lcm(a[0],a[1])
	for i in range(x):
		chk=lcm(chk,a[i])
	for i in range(x):
		ans=ans+(chk//a[i])
	print(ans%(10**9+7))

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

L=A[0]
for i in range(1,n):
    L=lcm(L,A[i])
ans=0
for i in range(n):
    ans+=(L*pow(A[i],mod-2,mod))%mod
print(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()))

L=A[0]
for i in range(1,n):
    L=lcm(L,A[i])
L%=mod
ans=0
for i in range(n):
    ans+=L*pow(A[i],mod-2,mod)
print(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()))

L=A[0]
for i in range(1,n):
    L=lcm(L,A[i])
L%=mod

coef=sum(pow(x,mod-2,mod) for x in A)
print(L*coef%mod)

Solution (Python):
from fractions import gcd

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

Solution (Python):

import sys
from functools import reduce
import fractions

MOD = 1000000007  

GCD_CACHE = {}


def gcd(x, y):
    if (x, y) in GCD_CACHE:
        return GCD_CACHE[(x, y)]
    d = fractions.gcd(x, y)
    GCD_CACHE[(x, y)] = d
    return d


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


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


def solve(N: int, A: "List[int]"):
    m = lcm(*A) % MOD
    sum = 0
    for a in A:
        sum = (sum + m*pow(a, MOD-2, MOD)) % MOD
    print(sum)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd
def main():
    N=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    b=0
    c=1
    for a in A:
        c=c*a//gcd(c,a)
    c%=mod
    for a in A:
        b+=c*pow(a,mod-2,mod)
    print(b%mod)
if __name__=="__main__":
    main()

Solution (Python):
import collections
nmax = 10**6+1
mod = 10**9+7

fac = [1]*nmax
finv = [1]*nmax
inv = [1]*nmax
def ncr_pre():
    for i in range(2,nmax):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i] %mod

def factorize(n):
    b = 2
    fct = [(1,1)]
    while b * b <= n:
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
        b = b + 1
    if n > 1:
        fct.append((n,1))
    return fct

ncr_pre()

n = int(input())
a = list(map(int,input().split()))
co = collections.Counter()
for i in range(n):
    for num,cnt in factorize(a[i]):
        co[num] = max(co[num],cnt)

lcm= 1
for num,cnt in co.items():
    lcm *= num**cnt
    lcm%=mod

ans = 0
for i in range(n):
    ans += lcm*inv[a[i]]
    ans %=mod
print(ans)

Solution (Python):
import math
MOD=10**9+7
MAX=10**6
sq_max=int(math.sqrt(MAX))

seive=[1 for _ in range(MAX+1)]
seive[0]=0
seive[1]=0
for i in range(sq_max+1):
  if seive[i]==0:
    continue
  for j in range(i*2,MAX+1,i):
    seive[j]=0

def factor(num):
  factordic={}
  for i in range(2,min([MAX+1,int(math.sqrt(num))+1])):
    if seive[i]==1 and num%i==0:
      factordic[i]=1
      num//=i
      while num%i==0:
        factordic[i]+=1
        num//=i
    if num==1:
      break
  else:
    factordic[num]=1
  return(factordic)


inv=[1,1]
for i in range(2, MAX+1):
  inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)

N=int(input())
ls=[int(s) for s in input().split()]
lcm={}
for num in ls:
  d=factor(num)
  for key,value in d.items():
    if key in lcm:
      lcm[key]=max(value,lcm[key])
    else:
      lcm[key]=value
lcmmod=1
for key,value in lcm.items():
  lcmmod=(lcmmod*(key**value))%MOD
invsum=0
for e in ls:
  invsum=(invsum+inv[e])%MOD
print((invsum*lcmmod)%MOD)

Solution (Python):
import math
MOD=10**9+7
MAX=10**6
sq_max=int(math.sqrt(MAX))

seive=[1 for _ in range(MAX+1)]
seive[0]=0
seive[1]=0
for i in range(sq_max+1):
  if seive[i]==0:
    continue
  for j in range(i*2,MAX+1,i):
    seive[j]=0

def factor(num):
  factordic={}
  for i in range(2,min([MAX+1,int(math.sqrt(num))+1])):
    if seive[i]==1 and num%i==0:
      factordic[i]=1
      num//=i
      while num%i==0:
        factordic[i]+=1
        num//=i
    if num==1:
      break
  else:
    factordic[num]=1
  return(factordic)


inv=[1,1]
for i in range(2, MAX+1):
  inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)

N=int(input())
ls=[int(s) for s in input().split()]
lcm={}
for num in ls:
  d=factor(num)
  for key,value in d.items():
    if key in lcm:
      lcm[key]=max(value,lcm[key])
    else:
      lcm[key]=value
lcmmod=1
for key,value in lcm.items():
  lcmmod=(lcmmod*(key**value))%MOD
invsum=0
for e in ls:
  invsum=(invsum+inv[e])%MOD
print((invsum*lcmmod)%MOD)

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

def fa(n):
    arr = []
    temp = n
    m = int(n**0.5//1)
    for i in range(2, m+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

l = []
for i in range(n):
	deg = fa(a[i])
	if i == 0:
		l = deg
	else:
		for j in range(len(deg)):
			for k in range(len(l)):
				if deg[j][0] == l[k][0]:
					l[k][1] = max(l[k][1], deg[j][1])
					break
			else:
				l.append(deg[j])
lcm = 1
for fac in l:
	factors = pow(fac[0], fac[1], MOD)
	lcm = (lcm*factors)%MOD
ans = 0
for i in range(n):
	ans += pow(a[i], MOD-2, MOD)
print((ans*lcm)%MOD)

Solution (Python):
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]

n = INT()
a = LIST()
l = 1
for i in a:
    l = lcm(l, i)
l %= mod
ans = 0
for i in a:
    ans += l * pow(i, mod - 2, mod)
print(ans % mod)

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

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

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

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

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

Solution (Python):
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
cmnd = defaultdict(int)

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

lcm = 1
for k,v in cmnd.items():
    for i in range(v):
        lcm = (lcm * k) % MOD

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

print(ans)

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

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    l = 1
    for x in a:l = lcm(l, x)
    ans = 0
    for x in a:
        ans+=l//x

    print(ans%1000000007)
main()

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

Solution (Python):
import sys

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b 

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    mod = 7 + 10 ** 9
    gcdA = A[0]
    lcmA = A[0]
    for i in range(1, N):
        gcdA = gcd(lcmA, A[i])
        lcmA = (lcmA * A[i]) // gcdA
    lcmA %= mod
    Ans = 0
    for a in A:
        Ans += (lcmA * pow(a, mod - 2, mod)) % mod
        Ans %= mod
    print(Ans)


    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
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_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)

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
M=10**9+7

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

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

t=0
for i in range(N):
  t=(t+l*pow(A[i],M-2,M))%M

print(t%M)

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()))
mod = 10 ** 9 + 7
lcm_val = A[0]
for a in A[1:]:
    lcm_val = lcm(lcm_val, a)

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

Solution (Python):
import functools
"""最大公約数"""
def gcd(a,b):
    import fractions
    return fractions.gcd(a,b)

"""最小公倍数"""
def lcm(a,b):
    f = gcd(a,b)
    return a*b//f

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

def main():
    n = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    l = m(A)
    res = 0
    print(sum(l// i for i in A) % mod)

if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd
from functools import reduce

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

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    x = reduce(lcm, a)
    print(sum(x // i for i in a) % mod)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

n = int(input())
a = [int(x) for x in input().split()]
am = max(a)
mod = 10**9+7
if n==1:
    print(1)
    sys.exit()
li = [0]*(am+1)
lcm = 1
for k in range(n):
    z = a[k]
    for i in range(2,int(z**0.5)+1):
        x = 0
        while z%i==0:
            x += 1
            z//=i
        li[i] = max(li[i],x)
    if z!=1 and li[z]==0:
        li[z] = 1

for i in range(2,am+1):
    if li[i]>0:
        lcm = lcm * i**li[i] % mod

ans = 0
for i in range(n):
    m = pow(a[i],mod-2,mod)
    ans = (ans+(lcm*m)%mod)%mod
print(ans%mod)

Solution (Python):

from fractions import gcd
from functools import reduce

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

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

print(sum(x // ai for ai in a) % mod)

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

Solution (Python):
mod = 10**9+7
from fractions import gcd
def lcm(list):
    num = 1
    for x in list:
        num = num//gcd(num, x)*x
    return num%mod

def Pow(a,n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod

N = int(input())
A = list(map(int, input().split()))
M = lcm(A)
R = [0]*N
for i in range(N):
    R[i] = Pow(A[i],mod-2)
ans = 0
for i in range(N):
    ans = (ans+M*R[i])%mod
print(ans)

Solution (Python):
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip(listed=True)

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()