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

MOD = 10 ** 9 + 7

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

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

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
tmp %= MOD

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

Solution (Python):
MOD = 10**9+7

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

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

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

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

LCM %= MOD

def pow(a,n,mod):
    ret = 1
    tmp = a
    while n:
        if n & 1:
            ret *= tmp
            ret %= mod
        tmp *= tmp
        tmp %= mod
        n >>= 1
    return ret

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


ans = 0
for v in a:
    ans += LCM * inv(v,MOD)
    ans %= MOD;

print(ans)

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

MOD = 10 ** 9 + 7

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

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

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
tmp %= MOD

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

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

MOD = 10 ** 9 + 7

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

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

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
tmp %= MOD

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

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

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

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

N = ir()
A = lr()
A.sort()
if N == 1:
    print(1)
    exit()
MOD = 10 ** 9 + 7
l = []
first = A[0]
l = [x//gcd(x, first) for x in A[1:]]
x = lcm(l) 
answer = x%MOD

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

print(answer%MOD)

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

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())
a = list(map(int, input().split()))

g = 1
for i in a:
    g = lcm(g, i)

ans = 0
for i in a:
    ans += g // i

print(ans % mod)

Solution (Python):
import fractions


mod = 10 ** 9 + 7

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


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

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

ans = 0
for a in A:
    ans += num // 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)

INF=10**9+7

N=int(input())
A=[int(i) for i in input().split()]

temp=A[0]
for i in range(1,N):
    temp=lcm(temp,A[i])

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

print(ans%INF)

Solution (Python):
from fractions import gcd
P = 10**9 + 7
N = 1000001 
inv = [0] + [1] 
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
n=int(input())
a=list(map(int,input().split()))
lcm=a[0]
mod=10**9+7
for i in range(1,n):
  lcm=(lcm//gcd(lcm,a[i]))*a[i]
ans=0
lcm%=mod
for i in range(n):
  ans=(ans+lcm*inv[a[i]])%mod
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)
B = int(input())
L = list(map(int, input().split()))
d=L[0]
mod=1000000007
for i in range(B):
  d=lcm(d,L[i])
ans=0
for i in range(B):
  ans+=d//L[i]
print(ans%mod)

Solution (Python):
from fractions import gcd
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7


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

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

    print(sum([l // a for a in A]) % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])

MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
print(ans%MOD)

Solution (Python):
def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)


def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)


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

MAX_a = max(a)
iinv = [1] * (MAX_a + 1)
for i in range(2, MAX_a + 1):
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD

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

lcm %= MOD

ans = 0
for i in range(n):
    ans += lcm * iinv[a[i]]
    ans %= MOD

print(ans)

Solution (Python):
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
L = A[0]
for a in A[1:]:
    L = L * a // gcd(L, a)

ans = 0
for a in A:
    ans += L // a

print(ans%1000000007)

Solution (Python):
from functools import reduce
import fractions
 
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())

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

lcm = lcm_list(inp_list)

ans = 0

for i in inp_list:
    ans += lcm // i


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

Solution (Python):
from functools import reduce
import fractions
 
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())

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

lcm = lcm_list(inp_list)

ans = 0
mod = 10**9+7

for i in inp_list:
    ans += lcm // i



print(ans % mod)

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


lcm_a = lcm_list(Alist)
mod = 10**9 + 7
ans = 0

for a in Alist:
    ans += (lcm_a // a)
print(ans % mod)

Solution (Python):
import functools
import fractions
MOD = 10**9+7


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


def lcm(numbers):
    return functools.reduce(lcm_base, numbers, 1)


def main():
    n = int(input())
    x = list(map(int, input().split()))

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

    print(ans % MOD)


main()

Solution (Python):


from fractions import gcd
iim = lambda: map(int, input().rstrip().split())

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))
    return ans

def resolve():
    N = int(input())
    A = list(iim())
    mod = 10**9 + 7

    lcm = 1
    
    
    
    
    
    
    

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

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

    print(s)

if __name__ == "__main__":
    resolve()

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))
    return ans

def resolve():
    N = int(input())
    A = list(iim())
    mod = 10**9 + 7

    c = 1
    c2 = dict()
    for a in A:
        for n, m in factor(a):
            if n in c2:
                c2[n] = max(c2[n], m)
            else:
                c2[n] = m

    c3 = 1
    for n, m in c2.items():
        c3 *= n**m%mod % mod

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

    print(s)

if __name__ == "__main__":
    resolve()

Solution (Python):
from fractions import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

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

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

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

for i in range(N):
    answer += LCM // A[i]

print(answer % mod)

Solution (Python):
from fractions import gcd 

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

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

lcm_number=1

for i in range(N):
   lcm_number=lcm(lcm_number,A[i])

count=0
for i in range(N):
   count+=lcm_number//A[i]

print(count%(10**9+7))

Solution (Python):

import fractions
from functools import reduce
 
MOD = 10**9 + 7
 
def main():
    N = int(input())
    A = list(map(int, input().split()))
 
    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 x in A:
        ans += l // x
        
    print(ans % MOD)
 
    
if __name__ == "__main__":
    main()

Solution (Python):

import fractions
from functools import reduce
 
MOD = 10**9 + 7
 
def main():
    N = int(input())
    A = list(map(int, input().split()))
 
    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 x in A:
        ans += l // x
        
    print(ans % MOD)
 
    
if __name__ == "__main__":
    main()

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD

def factorize(num: int) -> dict:
    """ 素因数分解 """
    from math import sqrt
    from collections import Counter

    d = Counter()
    
    for i in range(2, int(sqrt(num))+1):
        
        while num % i == 0:
            num //= i
            d[i] += 1
        
        if num == 1:
            break
    
    if num != 1:
        d[num] += 1
    return d

def mul(C1, C2):
    return C1 + C2

def div(C1, C2):
    return C1 - C2

def gcd(C1, C2):
    return C1 & C2

def lcm(C1, C2):
    for k, v in C2.items():
        C1[k] = max(C1[k], v)
    return C1
    

N = INT()
A = LIST()


A2 = [factorize(a) for a in A]
l2 = Counter()
for a in A2:
    l2 = lcm(l2, a)


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

ans = 0
for a in A:
    ans += fermat(l, a, MOD)
    ans %= MOD
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class mint:
    def __init__(self, x):
        self.__x = x % md

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

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

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

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

md = 10 ** 9 + 7
def main():
    n = II()
    aa = LI()
    l = 1
    for a in aa:
        l = lcm(l, a)
    l = mint(l)
    ans = sum(l / a for a in aa)
    print(ans)

main()

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD

def factorize(num: int) -> dict:
    """ 素因数分解 """
    from math import sqrt
    from collections import Counter

    d = Counter()
    
    for i in range(2, int(sqrt(num))+1):
        
        while num % i == 0:
            num //= i
            d[i] += 1
        
        if num == 1:
            break
    
    if num != 1:
        d[num] += 1
    return d

def mul(C1, C2):
    return C1 + C2

def div(C1, C2):
    return C1 - C2

def gcd(C1, C2):
    return C1 & C2

def lcm(C1, C2):
    return C1 | C2

N = INT()
A = LIST()


A2 = [factorize(a) for a in A]
l2 = Counter()
for a in A2:
    for k, v in a.items():
        l2[k] = max(l2[k], v)


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

ans = 0
for a in A:
    ans += fermat(l, a, MOD)
    ans %= MOD
print(ans)

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

mod = 10 ** 9 + 7
n = int(input())
l = [int(i) for i in input().split()]
product  = 1
for i in l:
    product = lcm(product,i)

ans = 0 
for i in l:
    ans += product // i
ans %= mod
    
print(ans)

Solution (Python):
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
def lcm_n(nums):
    return functools.reduce(lcm, nums)

n = ni()
a = na()
a_lcm = lcm_n(a)
ans = 0
for ai in a:
    ans += a_lcm // ai
ans %= mod
print(ans)

Solution (Python):
from fractions import gcd 
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
l = 1
for i in range(n):
    l = a[i]*l // gcd(l, a[i])


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

d = 0
for i in range(n):
    d += modinv(a[i])

print((l*d) % mod)

Solution (Python):
from fractions import gcd 
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
l = 1
for i in range(n):
    l = a[i] // gcd(l, a[i]) * l
    

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

d = 0
for i in range(n):
    d += modinv(a[i])

print((l*d) % 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()))
a_lcm=A[0]
Mod=10**9+7

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])



result=0
for i in range(N):
    result+=a_lcm*pow(A[i],Mod-2,Mod)
print(result%1000000007)

Solution (Python):
from fractions import gcd

def solve():
    n = int(input())
    a = list(map(int,input().split()))
    x = 1
    for ai in a:
        x = (x * ai) // gcd(x, ai)
    ans = sum([x // ai for ai in a])
    print(ans % 1000000007)

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

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


def lcmlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(lcm,lista)
LCM = lcmlist(A)
ans = 0
for i in A:
    ans += LCM//i
print(ans%mod)

Solution (Python):
import sys
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return abs(a)

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

n, *A = map(int, sys.stdin.read().split())

def main():
    l = reduce(lcm, A, 1) % MOD

    res = 0
    for a in A:
        res += l * pow(a, MOD-2, MOD) % MOD
        res %= MOD
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

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()))
a_lcm=A[0]
Mod=10**9+7

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])

a_lcm%=Mod

result=0
for i in range(N):
    result+=a_lcm*pow(A[i],Mod-2,Mod)
print(result%1000000007)

Solution (Python):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
LCM = 1
for i in A:
    GCD = gcd(LCM,i)
    LCM = LCM*i//GCD
ans = 0
for i in A:
    ans += LCM//i
print(ans%mod)

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

Solution (Python):
from fractions import gcd


def solve():
    N, *A = map(int, open(0).read().split())
    MOD = 10 ** 9 + 7

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

    ans = [lcm // a for a in A]
    print(sum(ans) % MOD)


if __name__ == '__main__':
    solve()

Solution (Python):
a = int(input())
l = list(map(int,input().split()))

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


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

MOD = 10**9+7
ans = 0
t = 1
for i in l:
    t = lcm(t,i)

for i in l:
    ans +=t//i
print(ans%MOD)

Solution (Python):
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

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

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

n = int(input())
A = list(map(int, input().split()))
k = lcm_list(A)
r = 0
ln = list(range(n))
for i in ln:
    r += k//A[i]
print(r%(10**9+7))

Solution (Python):
from collections import defaultdict
import math
sieve=[1]*10001
i=2
while i*i<=10001:
    if sieve[i]:
        for j in range(i+i,10001,i):
            sieve[j]=0
        
    i+=1    
lol=[]
for i in range(2,10001):
    if sieve[i]:
        lol.append(i)
mod=10**9+7
def gcd(x,y):
    if x==0:
        return y
    return gcd(y%x,x)    
x=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for i in a:
    k=0

    while lol[k]*lol[k]<=i:
        c=0
        
        j=lol[k]
        if i%j==0:    
            while i%j==0:
                i//=j
                c+=1
            d[j]=max(c,d[j])    
        k+=1    
    if i>=2:
        c=1
        d[i]=max(c,d[i])
        
y=0
s=d.keys()

z=1
for i in s:
    z*=pow(i,d[i])
for i in a:
    y+=((z%mod)*pow(i,mod-2,mod))%mod
print(y%mod)

Solution (Python):
from collections import Counter

mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

C = Counter()
for a in A:
    if a in C:
        continue

    i = 2
    while i * i <= a:
        if a % i == 0:
            cnt = 0
            while a % i == 0:
                a //= i
                cnt += 1
            C[i] = max(C[i], cnt)
        i += 1
    if a > 1:
        C[a] = max(C[a], 1)

L = 1
for i, c in C.items():
    L *= pow(i, c, mod)
    L %= mod

print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

Solution (Python):






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

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

MOD = 10 ** 9 + 7

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

c = p[0]
for x in p[1:]:
    c = c * x // gcd(c, x)

ans = 0
for x in p:
    ans += c // x

print(ans % MOD)

Solution (Python):
from fractions import gcd
from functools import reduce
mod=1000000000+7
n=int(input())
a=[int(i) for i in input().split()]
l=reduce(lambda x,y:x//gcd(x,y)*y,a)
ans=sum(map(lambda x:l//x,a))
print(ans%mod)

Solution (Python):
def main():
    from fractions import gcd
    from functools import reduce
    mod=1000000000+7
    n=int(input())
    a=[int(i) for i in input().split()]
    l=reduce(lambda x,y:x//gcd(x,y)*y,a)
    ans=sum(map(lambda x:l//x,a))
    print(ans%mod)
main()

Solution (Python):
def main():
    from fractions import gcd
    from functools import reduce
    def lcm(c,d):
        return c//gcd(c,d)*d
    mod=1000000000+7
    n=int(input())
    a=[int(i) for i in input().split()]
    l=reduce(lcm,a)
    ans=sum(map(lambda x:l//x,a))
    print(ans%mod)
main()

Solution (Python):
def main():
    from fractions import gcd
    from functools import reduce
    def lcm(c,d):
        return c//gcd(c,d)*d
    mod=10**9+7
    n=int(input())
    a=[int(i) for i in input().split()]
    l=reduce(lcm,a)
    ans=sum(map(lambda x:l//x,a))
    print(ans%mod)
main()

Solution (Python):
import sys

MOD = 10 ** 9 + 7

from math import floor, sqrt
from bisect import bisect_right as bi_r
from collections import defaultdict

def prime_nums(n=10**6):
    sieve = set(range(2, n + 1))
    non_prime = set(range(2 * 2, n + 1, 2))
    sieve -= non_prime
    for i in range(3, floor(sqrt(n)) + 1, 2):
        if i in sieve:
            non_prime = set(range(i * 2, n + 1, i))
            sieve -= non_prime
    return sieve

p_nums = sorted(prime_nums())

def make_inv_table(n=10**6, p=MOD):
    fac = [None] * (n + 1)
    fac[0] = 1
    for i in range(n):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (n + 1)
    ifac[n] = pow(fac[n], p-2, p)
    for i in range(n, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    inv = [None] * (n + 1)
    for i in range(1, n+1):
        inv[i] = ifac[i] * fac[i-1] % p
    return inv

inv = make_inv_table()

n, *A = map(int, sys.stdin.read().split())

def main():
    facs = defaultdict(int)
    for a in A:
        if a == 1:
            continue
        for p in p_nums[:bi_r(p_nums, sqrt(a))]:
            cnt = 0
            while not a % p:
                cnt += 1
                a //= p
            facs[p] = max(facs[p], cnt)
            if a == 1:
                break
        else:
            facs[a] = max(facs[a], 1)
    
    lcm = 1
    for f, c in facs.items():
        lcm *= pow(f, c, MOD)
        lcm %= MOD
    
    ans = 0
    for a in A:
        ans += lcm * inv[a] % MOD
        ans %= MOD
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

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

Solution (Python):
import fractions as math
from functools import reduce
 
 
N = int(input())
A=list(map(int, input().split()))
 
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
num = lcm_list(A)
 
ans = 0
 
for i in range(N):
    ans += (num // A[i])
 
print(ans%(10**9+7))

Solution (Python):
def main():
    from fractions import gcd
    def lcm(c,d):
        return c//gcd(c,d)*d
    mod=10**9+7
    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%mod)
main()

Solution (Python):
def main():
    from fractions import gcd
    def lcm(c,d):
        return c//gcd(c,d)*d
    mod=10**9+7
    n=int(input())
    a=[int(i) for i in 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//a[i]
    print(ans%mod)
main()

Solution (Python):
def main():
    from fractions import gcd
    def lcm(c,d):return c//gcd(c,d)*d
    mod=10**9+7
    n=int(input())
    a=[int(i) for i in 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//a[i]
    print(ans%mod)
main()

Solution (Python):
from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in 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//a[i]
    
print(ans%mod)

Solution (Python):
from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in 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//a[i]
    
print(ans%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
 
def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n
 
def lcm(n, m):
    return n // gcd(n, m) * m
 
LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)
 
res = 0
MOD = 1000000007
for i in range(n):
    res += LCM//a[i]
    
print(res % MOD)

Solution (Python):
import fractions
N=int(input())
a = list(map(int, input().split()))


lcm = a[0]
for i in range(1, N):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])

ans=0
for j in a:
    ans += lcm // j
print(ans % 1000000007)

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

lcm = lambda a, b: b // gcd(a, b) * a
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

L = reduce(lcm, A) % mod
print(L * sum(pow(a, mod - 2, mod) for a in A) % mod)

Solution (Python):




import sys
input = sys.stdin.readline

import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
        return functools.reduce(multiple, nums)


N=int(input())
a=list(map(int,input().split()))
calc=(lcm(a))  


ans=0
for index,item in enumerate(a):
    ans+=(calc)//item

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

Solution (Python):
import functools
import fractions

MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]

L = functools.reduce(lambda a, b: a // fractions.gcd(a, b) * b, A) % MOD
ans = 0

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

print(ans)

Solution (Python):
from fractions import gcd
n = int(input())
lcm = list(map(int, input().split()))
ans = [1] * n
while len(lcm) < (1 << 14):
  lcm.append(1)
  ans.append(0)
for i in range(13, -1, -1):
  bit = 1 << i
  for j in range(bit):
    new = lcm[j] // gcd(lcm[j], lcm[j | bit]) * lcm[j | bit]
    ans[j] = new // lcm[j] * ans[j] + new // lcm[j | bit] * ans[j | bit]
    lcm[j] = new
print(ans[0] % 1000000007)

Solution (Python):
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
lcm = 1
for a in A:
    lcm = a // gcd(lcm, a) * lcm
ans = 0
for a in A:
    ans += lcm // a
ans %= MOD
print(ans)

Solution (Python):
from fractions import gcd
n = int(input())
lcm = list(map(int, input().split()))
ans = [1] * n
while len(lcm) < (1 << 14):
  lcm.append(1)
  ans.append(0)
for i in range(13, -1, -1):
  bit = 1 << i
  for j in range(bit):
    new = lcm[j] // gcd(lcm[j], lcm[j | bit]) * lcm[j | bit]
    ans[j] = new // lcm[j] * ans[j] + new // lcm[j | bit] * ans[j | bit]
    ans[j] %= 1000000007
    lcm[j] = new
print(ans[0])

Solution (Python):
from fractions import gcd
n = int(input())
lcm = list(map(int, input().split()))
ans = [1] * n
while len(lcm) < (1 << 14):
  lcm.append(1)
  ans.append(0)
for i in range(13, -1, -1):
  bit = 1 << i
  for j in range(bit):
    new = lcm[j] // gcd(lcm[j], lcm[j | bit]) * lcm[j | bit]
    ans[j] = new // lcm[j] * ans[j] + new // lcm[j | bit] * ans[j | bit]
    ans[j] %= 1000000007
    lcm[j] = new
print(ans[0])

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

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

lcm = lambda a, b: b // gcd(a, b) * a
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

L = reduce(lcm, A) % mod
print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

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

lcm = lambda a, b: b // gcd(a, b) * a
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

L = reduce(lcm, A) % mod
print(sum(L * pow(a, mod - 2, mod) % mod for a in A) % mod)

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

lcm = lambda a, b: b // gcd(a, b) * a
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

L = reduce(lcm, A)
print(sum(L // a for a in A) % mod)

Solution (Python):
from fractions import gcd

mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

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

L %= mod

print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

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)