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):
from collections import defaultdict

class LCM_mod:
    """
    最小公倍数の計算を行う
    オーバーフローが発生しないように素因数分解し,
    因数の積を逐次余りに置き換えて最小公倍数を導出する.
    """
    def __init__(self, max_num, p=10**9+7):
        self.max_num = max_num + 1
        self.p = p
        self.prime = [0 for _ in range(self.max_num)]
        self.max_map = defaultdict(int)
        self.sieve()

    def rep_sqr(self, base, k):
        
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k / 2) ** 2) % self.p
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.p

    def sieve(self):
        """
        エラトステネスの篩　O(n)
        nまでに含まれる素数を導出
        """
        self.prime[0], self.prime[1] = 1, 1
        for i in range(2, self.max_num):
            if self.prime[i] == 0:
                for j in range(i * 2, self.max_num, i):
                    if self.prime[j] == 0:
                        self.prime[j] = i
                self.prime[i] = i

    def lcm_list_mod(self, arr):
        """
        listのそれぞれの要素について、素因数分解する
        それぞれの因数について最大であれば更新する
        """
        for i in range(len(arr)):
            num = arr[i]
            d = defaultdict(int)

            while num > 1:
                fact = self.prime[num]
                d[fact] += 1
                num //= fact

            for i in d.keys():
                self.max_map[i] = max(self.max_map[i], d[i])

        ans = 1
        for i in self.max_map.keys():
            ans = (ans * self.rep_sqr(i, self.max_map[i])) % self.p
        return ans


class FLT:
    def __init__(self, mod=10**9+7):
        self.mod = mod

    def rep_sqr(self, base, k):
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k // 2) ** 2) % self.mod
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.mod

    def inv(self, a):
        """ 逆元を取る """
        return self.rep_sqr(a, self.mod-2)

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

lcm_mod = LCM_mod(max(a), MOD)
lcm_all = lcm_mod.lcm_list_mod(a)
flt = FLT(MOD)

b = list(map(lambda x: lcm_all * flt.inv(x), a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)

Solution (Python):
from fractions import gcd

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

d = int(input())
nums = list(map(int, input().split(' ')))

lcm_num = 1
for n in nums:
  lcm_num = lcm_base(lcm_num, n)

ans = 0
mod = 10**9 + 7
for n in nums:
  ans += lcm_num//n
print(ans % mod)

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

lcm_A = 1
for i in range(N):
    lcm_A = lcm(lcm_A, A[i])
    
ans = 0
for i in range(N):
    ans += lcm_A // A[i]

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

Solution (Python):
from fractions import gcd

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

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

ans = 0
for a in A:
  ans += (l//a)

print(ans%MOD)

Solution (Python):
from fractions import gcd

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

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

ans = 0
for i in range(N):
    ans += lm//A[i]
ans %= Mod

print(ans)

Solution (Python):
from fractions import gcd
from functools import reduce
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
R = 10**9+7

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

def inv(x):
    return pow(x,R-2,R)

n = inn()
a = inl()



l = reduce(lcm_base,a,1)
sm = 0
for i in range(n):
    sm = (sm + inv(a[i]))%R
print((sm*l)%R)

Solution (Python):



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

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

def eratosthenes(n): 
    A = [0] * n
    A[0], A[1] = -1, -1
    for i in range(2, n):
      if A[i] == 0:
        j = i
        while j < n:
          A[j] = i
          j += i
    return A

E = eratosthenes(10**6+5)
l = {}

for a in A:
  now = a
  f = [] 

  while now > 1:
    f.append(E[now])
    now //= E[now]

  chk = 0 

  for p in f:
    if chk == p: 
      continue
    chk = p
    if p in l.keys(): 
      l[p] = max(l[p], f.count(p))
    else: 
      l[p] = f.count(p)
 
lcm = 1
for k in l:
  for i in range(l[k]):
      lcm= lcm * k % mod

s = 0
for i in range(N):
    s += lcm * inverse(A[i])
    s %= mod
print(s)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False
        self.ds_memo = {}
        self.ds_memo[1] = set([1])

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d


def M(n): return ModInt(n)
def MI(): return M(I())

class ModInt():
    def __init__(self, n):
        self.n = n

    def __add__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n+x) % mod)

    def __sub__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n-x) % mod)

    def __mul__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n*x) % mod)

    def __truediv__(self, x):
        x = ModInt.xn(x)
        return ModInt(self.n * pow(x, mod-2, mod) % mod)

    @classmethod
    def xn(cls, x):
        if isinstance(x, ModInt):
            return x.n
        return x

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

def main():
    n = I()
    a = LI()
    pr = Prime(10**12)
    ad = collections.defaultdict(int)
    da = []
    for c in a:
        d = pr.division(c)
        for k,v in d.items():
            if ad[k] < v:
                ad[k] = v
        da.append(d)
    ai = M(1)
    for k,v in ad.items():
        ai *= pow(k, v, mod)

    r = M(0)
    for c in a:
        r += ai / c

    return r


print(main())

Solution (Python):



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

def inverse(a): 
  T=[a]
  while 2**(len(T))<mod: 
      T.append(T[-1]**2%mod)
  b=bin(mod-2) 
  ans=1
  for i in range(len(b)-2):
      if int(b[-i-1])==1:
          ans=ans*T[i]%mod
  return ans

def eratosthenes(n): 
    A = [0] * n
    A[0], A[1] = -1, -1
    for i in range(2, n):
      if A[i] == 0:
        j = i
        while j < n:
          A[j] = i
          j += i
    return A

E = eratosthenes(10**6+5)
l = {}

for a in A:
  now = a
  f = [] 

  while now > 1:
    f.append(E[now])
    now //= E[now]

  chk = 0 

  for p in f:
    if chk == p: 
      continue
    chk = p
    if p in l.keys(): 
      l[p] = max(l[p], f.count(p))
    else: 
      l[p] = f.count(p)
 
lcm = 1
for k in l:
  for i in range(l[k]):
      lcm= lcm * k % mod

s = 0
for i in range(N):
    s += lcm * inverse(A[i]) % mod
    s %= mod
print(s)

Solution (Python):
from collections import defaultdict


def prime_decomposition(n):
    table = defaultdict(int)

    i = 2
    while n % i == 0:
        n //= i
        table[i] += 1

    i = 3
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i] += 1
        i += 2

    if n > 1:
        table[n] += 1

    return table


def main():
    mod = 10 ** 9 + 7

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

    lcm_d = defaultdict(int)
    for x in a:
        pd = prime_decomposition(x)
        for prime, power in pd.items():
            lcm_d[prime] = max(lcm_d[prime], power)

    lcm_ = 1
    for prime, power in lcm_d.items():
        lcm_ = (lcm_ * pow(prime, power, mod)) % mod

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = (ret * lcm_) % mod

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):


class Sieve:
    """区間[2,n]の値を素因数分解する"""

    def __init__(self, n=1):
        primes = []
        f = [0] * (n + 1)
        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.primes = primes
        self.f = f

    def is_prime(self, x) -> bool:  
        return self.f[x] == x

    def factor_list(self, x) -> list:  
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  
        fl = self.factor_list(x)
        if not fl: return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res


def main():
    from collections import defaultdict

    mod = 10 ** 9 + 7

    _ = int(input())  
    *a, = map(int, input().split())

    sieve = Sieve(n=10 ** 6 + 5)

    mp = defaultdict(int)
    for x in a:
        f = sieve.factor(x=x)  
        for prime, cnt in f:
            mp[prime] = max(mp[prime], cnt)

    lcm = 1
    for prime, cnt in mp.items():
        for _ in range(cnt):
            lcm = (lcm * prime) % mod

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


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd  

MOD=1000000007

def ADD(x, y):
  return (x + y) % MOD

def SUB(x, y):
  return (x - y + MOD) % MOD

def MUL(x, y):
  return x * y % MOD

def POW(x, e):
  v = 1
  while e:
    if e & 1:
      v = MUL(v, x)
    x = MUL(x, x)
    e >>= 1
  return v

def INV(x):
  return POW(x, MOD-2)

def DIV(x, y):
  return MUL(x, INV(y))


n = int(input().rstrip())
a = [int(x) for x in input().rstrip().split()]

el = 1
for ai in a:
  g = gcd(el,ai)
  el = el // g * ai

el %= MOD

sum = 0
for ai in a:
  sum += DIV(el, ai)

sum %= MOD
print(sum)

Solution (Python):
from fractions import gcd  

MOD=1000000007

def ADD(x, y):
  return (x + y) % MOD

def SUB(x, y):
  return (x - y + MOD) % MOD

def MUL(x, y):
  return x * y % MOD

def POW(x, e):
  v = 1
  while e:
    if e & 1:
      v = MUL(v, x)
    x = MUL(x, x)
    e >>= 1
  return v

def INV(x):
  return POW(x, MOD-2)

def DIV(x, y):
  return MUL(x, INV(y))


n = int(input().rstrip())
a = [int(x) for x in input().rstrip().split()]

el = 1
for ai in a:
  g = gcd(el,ai)
  el = el // g * ai

el %= MOD

sum = 0
for ai in a:
  sum += DIV(el, ai)

sum %= MOD
print(sum)

Solution (Python):
from fractions import*;from functools import*;n,*a=map(int,open(0).read().split());l=reduce(lambda a,b:a*b//gcd(a,b),a);print(sum(l//i for i in a)%(10**9+7))

Solution (Python):
from fractions import gcd;from functools import reduce;n,*a=map(int,open(0).read().split());l=reduce(lambda a,b:a*b//gcd(a,b),a);print(sum(l//i for i in a)%1000000007)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)


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


mod = int(1e9 + 7)
n = int(input())
a = [int(i) for i in input().split()]
kek = 1
for i in range(n):
    kek = (kek * a[i]) // gcd(kek, a[i])
s = 0
for i in range(n):
    s += kek // a[i]
print(int(s % mod))

Solution (Python):
import math

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

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

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

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

ans = 0
for e in a:
    ans += now_lcm//e

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

Solution (Python):
from collections import Counter, defaultdict

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

max_A = max(A)
f = list(range(max_A + 1))
for i in range(2, int(max_A ** 0.5) + 1):
    if f[i] == i:
        f[i::i] = [i] * (max_A // i)


def factors(x):
    factor = defaultdict(int)
    while x != 1:
        factor[f[x]] += 1
        x //= f[x]
    return factor


L = defaultdict(int)
for i in range(N):
    Ai = factors(A[i])
    for p, index in Ai.items():
        L[p] = max(L[p], index)
lcm = 1
for p, index in L.items():
    if index == 0:
        continue
    lcm *= pow(p, index, MOD)
    lcm %= MOD

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

Solution (Python):
import fractions
import sys
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)

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

if N==1:
  print(1)
else:
  lcm_alist=lcm_list(alist)
  
  
  allsum=0
  for i in range(N):
    allsum+=lcm_alist//alist[i]
    
  
  print(allsum%(10**9+7))

Solution (Python):
from fractions import gcd

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

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

ans = 0
for i in range(N):
    ans += lm//A[i]
ans %= Mod

print(ans)

Solution (Python):
def factoring(M,n=2):
    if M==1: return {}
    for i in range(n,int(M**0.5)+1):
        if M%i==0:
            ret = factoring(M//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {M:1}

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

mod = 10**9+7

fac = {}

for a in A:
    tmp = factoring(a)
    for b,n in tmp.items():
        fac[b] = max(fac.get(b,1),n)
lcm = 1
for b,n in fac.items():
    lcm *= pow(b,n,mod)
    lcm %= mod
        
ans = 0
for a in A:
    ans += (lcm*pow(a,mod-2,mod))%mod
    ans %= mod
print(ans)

Solution (Python):



from functools import reduce
from fractions import gcd

MOD = 10**9+7

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

def main():
    N = int(input())
    a = [int(i) for i in input().split()]

    lcm = reduce(lcm_base, a, 1)
    lcm %= MOD
    
    b = sum(pow(i, MOD - 2, MOD) for i in a)
    b %= MOD
    ans = lcm * b

    print(ans % MOD)


if __name__ == "__main__":
    main()

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

input = sys.stdin.readline
MOD = 10 ** 9 + 7


def inverse(n, mod=10 ** 9 + 7):
    return pow(n, mod - 2, mod)


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

    L = reduce(lambda o1, o2: o1 // gcd(o1, o2) * o2, A)
    sigma_A_inv = sum([inverse(a) for a in A])

    print(L * sigma_A_inv % MOD)


if __name__ == '__main__':
    main()

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 *= a//gcd(lcm, a)

print(sum(lcm//a for a in A)%MOD)

Solution (Python):
import fractions
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
g = 1
res = 0
MOD = 10**9+7
for elem in a:
    tmp = g*elem//fractions.gcd(g,elem)
    res *= tmp//g
    g = tmp
    res += g//elem
print(res%MOD)

Solution (Python):
from functools import reduce

MOD = 10**9 + 7
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

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

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

lcm_ = lcm_list(a)
b = list(map(lambda x: lcm_//x, a))
ans = 0
for i in range(len(b)):
    ans += b[i]
print(ans% MOD)

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

def inverse(a): 
    T=[a]
    while 2**(len(T))<mod: 
        T.append(T[-1]**2%mod)
    b=bin(mod-2) 
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans

def make_eratosthenes(n): 
    A=[0]*n
    A[0],A[1]=-1,-1
    for i in range(2,n):
        if A[i]==0:
            j=i
            while j<n:
                A[j]=i
                j+=i
    return A

E=make_eratosthenes(10**6+5)

l={}
for a in A:
    now=a
    f=[] 
    while now>1:
        f.append(E[now])
        now//=E[now]
    chk=0 
    for p in f:
        if chk==p: 
            continue
        chk=p
        if p in l.keys(): 
            l[p]=max(l[p],f.count(p))
        else: 
            l[p]=f.count(p)

lcm=1
for k in l:
    for i in range(l[k]):
        lcm=lcm*k%mod
s=0
for i in range(n):
    s+=lcm*inverse(A[i])%mod
    s%=mod
print(s)

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
import collections
import math

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


def eratosthenes(n):  
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


def factorize(n, primes):        
    if n < 2:
        return dict()
    counter = collections.Counter()
    for p in primes:
        while n % p == 0:
            counter[p] += 1
            n //= p
        if n == 1:
            break
    if n > 1:
        counter[n] += 1
    return counter


if n == 1:
    print(1)
    exit()

sieve = eratosthenes(10 ** 3)
primes = [x for x, b in enumerate(sieve) if b]

lcm = collections.Counter()
for x in a:
    counter = factorize(x, primes)
    for p, k in counter.items():
        lcm[p] = max(lcm[p], k)
lcm_val = 1
for p, k in lcm.items():  
    lcm_val *= pow(p, k, MOD)
    


res = 0
for x in a:
    res += lcm_val * pow(x, MOD - 2, MOD)  
    res %= MOD
print(res)

Solution (Python):

import re
import math
import fractions


mod=int(10**9+7)

def lcm(a,b):
    return

def ac(N,A):
    l=A[0]
    for a in range(1,N):
        l=(l*A[a])//fractions.gcd(l,A[a])
    l%=mod
    ans=0
    for a in A:
        ans+=l*pow(a,mod-2,mod)
        ans%=mod
    return ans

def solve():
    return


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

Solution (Python):
import functools

MOD = 10**9 + 7


def lcm(a, b) -> int:
    c, d = a, b
    while d != 0:
        c, d = d, c % d
    return a // c * b


def inv_mod(x):
    return pow(x, MOD - 2)


def pow(x: int, n: int) -> int:
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * x % MOD
        x = x * x % MOD
        n >>= 1

    return res


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

    lcm_an = functools.reduce(lcm, an)
    lcm_an %= MOD

    ans = 0
    for a in an:
        ans = (ans + lcm_an * inv_mod(a)) % MOD

    print(ans)


if __name__ == '__main__':
    main()

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

n = input()
arr = list(map(int, input().split()))
tmp = arr[0]
for i in arr:
    tmp = tmp*i//gcd(tmp,i)
print(sum(tmp//a for a in arr) % (10**9+7))

Solution (Python):
import fractions
from functools import reduce

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

def list_lcm(*numbers):
    return reduce(lcm,numbers)

n=int(input())
a=list(map(int,input().split()))
l,ans,mod=list_lcm(*a),0,1000000007
print(sum(l//i for i in a)%mod)

Solution (Python):
import fractions
from functools import reduce

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

def list_lcm(*numbers):
    return reduce(lcm,numbers)

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

l=list_lcm(*a)
ans,mod=0,1000000007
for i in a:
    ans+=l//i

print(ans%mod)

Solution (Python):
import fractions as m
n=int(input())
a=input().split()
b=1
for i in a:
    i=int(i)
    b*=i//m.gcd(b,i)
    
print(sum(b//int(i) for i in a)%(10**9+7))

Solution (Python):
def gcd(x, y):
    while y > 0:
        tmp = x % y
        x = y
        y = tmp
    return x

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

def main():
    mod = int(1e9 + 7)
    n = int(input())
    a = list(map(int, input().split()))
    l = 1
    for i in range(n):
        l = lcm(l, a[i])

    ans = 0

    print(int(sum(l // i for i in a) % mod))

if __name__ == '__main__':
    main()

Solution (Python):
import fractions
import functools

MOD = int(1e9) + 7


def lcm(a, b):
    c, d = a, b
    while d != 0:
        c, d = d, c % d
    return a // c * b


class Inv:

    @classmethod
    def pow(cls, x: int, n: int) -> int:
        ret = 1
        while n > 0:
            if n % 2 == 1:
                ret = ret * x % MOD
            x = x * x % MOD
            n >>= 1
        return ret

    @classmethod
    def inv(cls, x: int) -> int:
        return cls.pow(x, MOD - 2)


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

v = functools.reduce(lcm, A)
v %= MOD
ans = 0
for a in A:
    ans = (ans + v * Inv.inv(a)) % MOD
print(ans)

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

def lcm(x, y):
    return (x * y) // gcd(x, y)
def main():
    n = int(sys.stdin.readline())
    a = list(map(int,input().split()))
    
    l = a[0]
    for i in range(n):
        l = lcm(l, a[i])
    sum = 0
    for i in range(n):
        sum += l // a[i]
    print(sum % 1000000007)
main()

Solution (Python):
from fractions import *
n,*a=map(int,open(0).read().split())
b=1
for i in a:b*=i//gcd(b,i)
print(sum(b//i for i in a)%(10**9+7))

Solution (Python):
from fractions import gcd
def lcm(a,b):
    return a//gcd(a,b)*b

n=int(input())
a=[int(i) for i in input().split()]
L=a[0]
for i in a:
    L=lcm(L,i)
ans=0
for i in a:
    ans+=L//i
print(ans%(10**9+7))

Solution (Python):
N=10**6+1
mod=10**9+7

inv_l=[0,1]
for i in range(2,N):
    inv_l+=[inv_l[mod%i]*(mod-int(mod/i))%mod]

prime_list=[]
min_prime=[1]*(N+1)
is_prime=[0,0]+[1]*(N-1)
for i in range(2,N+1):
    if is_prime[i]==1:
        prime_list.append(i)
        j=i
        while j<=N:
            is_prime[j]=0
            if min_prime[j]==1:
                min_prime[j]=i
            j+=i

def lcm(l,mod):
    max_count=[0]*(N+1)
    for a in l:
        a_min_prime=min_prime[a]
        a_count=0
        while a>1:
            if min_prime[a]==a_min_prime:
                a_count+=1
                a//=a_min_prime
            else:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
                a_min_prime=min_prime[a]
                a//=a_min_prime
                a_count=1
            if a==1:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
    ret=1
    for i in range(1,N+1):
        if max_count[i]!=0:
            ret=(ret*i**max_count[i])%mod
    return ret

n=int(input())
A=list(map(int,input().split()))
L=lcm(A,mod)
ans=0
for i in range(n):
    ans=(ans+L*inv_l[A[i]])%mod
print(ans)

Solution (Python):
from functools import reduce

def gcd(x, y):
    y, x = sorted([x, y])
    while True:
        r = x % y
        if r == 0:
            
            return y
        else:
            
            x, y = y, r

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

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

N = int(input())
l = list(map(int, input().split(" ")))

p = lcm_list(l)
c = 0
z = 10 ** 9 + 7
for i in l:
  c += p // i
print(c % z)

Solution (Python):
from fractions import gcd
import sys
input = sys.stdin.readline
def lcm(a,b):
    return a*b // gcd(a,b)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9+7
    l = 1
    for a in A:
        l = lcm(l,a)
    ans = 0
    for a in A:
        ans += l//a
    print(ans%M)
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from fractions import gcd
    import sys
    input = sys.stdin.readline
    def lcm(a,b):
        return a*b // gcd(a,b)
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9+7
    l = 1
    for a in A:
        l = lcm(l,a)
    ans = 0
    for a in A:
        ans += l//a
    print(ans%M)
if __name__ == '__main__':
    main()

Solution (Python):
def gcd(x, y):
    while y > 0:
        tmp = x % y
        x = y
        y = tmp
    return x

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

def main():
    mod = int(1e9 + 7)
    n = int(input())
    a = list(map(int, input().split()))
    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(int(ans))

if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd
def lcm(a,b):
    return a*b // gcd(a,b)

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

Solution (Python):
import fractions
import functools

MOD = int(1e9) + 7


class Inv:

    @classmethod
    def pow(cls, x: int, n: int) -> int:
        ret = 1
        while n > 0:
            if n % 2 == 1:
                ret = ret * x % MOD
            x = x * x % MOD
            n >>= 1
        return ret

    @classmethod
    def inv(cls, x: int) -> int:
        return cls.pow(x % MOD, MOD - 2)


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

MAX_A = 1000010

facts = [0] * MAX_A
p = [False] * MAX_A

def prime():

    for i in range(2, MAX_A):
        p[0] = p[1] = True
        if not p[i]:
            j = 2 * i
            while j < MAX_A:
                p[j] = True
                j += i

prime()

for a in A:
    i = 2
    while i * i <= a:
        if a % i == 0:
            ii = a // i
            c1 = 0
            while a % i == 0:
                c1 += 1
                a //= i
            c2 = 0
            while not p[ii] and a % ii == 0:
                c2 += 1
                a //= ii
            facts[i] = max(facts[i], c1)
            facts[ii] = max(facts[ii], c2)
        i += 1
    if not p[a]:
        facts[a] = max(facts[a], 1)

tar = 1
for idx, c in enumerate(facts):
    if c == 0:
        continue
    tar *= Inv.pow(idx, c)
    tar %= MOD

ans = 0
for a in A:
    ans += tar * Inv.inv(a) % MOD
    ans %= MOD

print(ans)

Solution (Python):
import time, math
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def f(a):
    M=10**9+7
    ans, z = 0, 1
    for x in a:
        z = (z * x) // gcd(z, x)
    
    z %= M
    for x in a:
        ans += z * pow(x, M-2, M)
        ans %= M
    return ans

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



print(f(a))

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

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

L = 1

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

L %= MOD
ans = 0

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

print(ans)

Solution (Python):
from collections import defaultdict

def factorize(n):
    factors = []
    
    for i in range(2, int(n**0.5)+1):
        cnt = 0
        
        while n%i==0:
            n //= i
            cnt += 1
            
        if cnt>0:
            factors.append((i, cnt))
    
    if n!=1:
        factors.append((n, 1))
    
    return factors
    
def inv(x):
    return pow(x, MOD-2, MOD)
    
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
M = defaultdict(int)

for Ai in A:
    factors = factorize(Ai)
    
    for v, c in factors:
        M[v] = max(M[v], c)
    
L = 1

for v, c in M.items():
    L *= pow(v, c, MOD)
    L %= MOD

ans = 0

for Ai in A:
    ans += L*inv(Ai)
    ans %= MOD

print(ans)

Solution (Python):
from fractions import *
n,*a=map(int,open(0).read().split())
mod=10**9+7
b=a[0]
for i in a:
    b=b*i//gcd(b,i)
print(sum(b//i for i in a)%mod)

Solution (Python):
from fractions import *
n,*a=map(int,open(0).read().split())
b=1
for i in a:b*=i//gcd(b,i)
print(sum(b//i for i in a)%(10**9+7))

Solution (Python):
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


def factorize(n, primes):
    import collections
    if n < 2:
        return dict()
    counter = collections.Counter()
    for p in primes:
        while n % p == 0:
            counter[p] += 1
            n //= p
        if n == 1:
            break
    if n > 1:
        counter[n] += 1
    return counter


MOD = 10**9 + 7

n = ri()
ls = ril()
if n == 1:
    print(1)
    exit()

sieve = eratosthenes(10**3)
primes = [x for x, b in enumerate(sieve) if b]

lcm_counter = collections.Counter()
for x in ls:
    counter = factorize(x, primes)
    for p, k in counter.items():
        lcm_counter[p] = max(lcm_counter[p], k)
lcm = 1
for p, k in lcm_counter.items():
    lcm *= pow(p, k, MOD)
    lcm %= MOD

res = 0
for x in ls:
    res += lcm * pow(x, MOD - 2, MOD)
    res %= MOD
print(res)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
 
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)
 
x = lcm_list(l)
ans = 0
for i in range(n):
  ans += x//l[i]
ans %= 10**9+7
  
print(ans)