Problem:


Score : 500 points

Problem Statement

Given are N positive integers A_1,...,A_N.

Consider positive integers B_1, ..., B_N that satisfy the following condition.

Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.

Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.

Since the answer can be enormous, print the sum modulo (10^9 +7).

Constraints

1 \leq N \leq 10^4

1 \leq A_i \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).

Sample Input 1

3
2 3 4

Sample Output 1

13

Let B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.

Sample Input 2

5
12 12 12 12 12

Sample Output 2

5

We can let all B_i be 1.

Sample Input 3

3
1000000 999999 999998

Sample Output 3

996989508

Print the sum modulo (10^9+7).



Sample input:
3
2 3 4


Sample output:
13

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
# from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
# from heapq import heappop, heappush, heappushpop
# from collections import Counter,defaultdict,deque
# from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N=I()
    A=LI()
    l = 1
    for a in A:
        l *= a//gcd(l,a)
    ans = 0
    l%=mod
    for a in A:
        ans += l * pow(a,mod-2,mod)
        ans %= mod
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,m = [int(i) for i in readline().split()]
#d = [int(i) for i in readline().split()]
MOD = 10**9+7

n = int(input())
a = [int(i) for i in readline().split()]

from fractions import gcd
m = a[0]
for i in a:
    m = i//gcd(m,i)*m

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

print(ans%MOD)

Submission status: Accepted

Solution code:
#a,bの最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

#a,bの最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

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

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

P = 10**9+7
ans = 0
for i in range(N):
    ans += l//A[i]
print(ans%P)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input().split()))
ans = 0
mod = int(1e9+7)
def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a
def lcm(a,b):
    return a // gcd(a,b) * b

g = 1
for i in range(n):
    g = lcm(g, s[i])
for i in range(n):
    ans += g // s[i]
print(ans%mod)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
def lcm(a,b):
  return a*b//fractions.gcd(a,b)
a_lcm = A[0]
for a in A[1:]:
  a_lcm = lcm(a_lcm, a)
ans = 0
for a in A:
  ans += a_lcm//a
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
import sys
input = sys.stdin.readline

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


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

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


n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=1)
ans=0
m=int(10**9+7)
g=1
l=1
'''
for x in a:
  if l%x!=0:
    g=gcd(l,x)
    l=l*x//g
'''
l=lcm(*a)

for x in a:
  ans+=l//x

print(ans%m)

Submission status: Accepted

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
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)
  ans%=mod
print(ans)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
b = []
b_sum = 0
mod = 10**9+7
for i in range(n):
    b_sum += (ans // a[i])

print(b_sum % mod)

Submission status: Accepted

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


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


mod = 10**9+7
lc = a[0]
for i in range(N):
    lc = lcm(lc, a[i])
ans = 0
for i in range(N):
    ans += (lc // a[i])
print(ans % mod)

Submission status: Accepted

Solution code:
mod = 1000000007
def gcd(a, b):
    while(b > 0):
        a = a%b
        c = b
        b = a
        a = c
    return a

n = int(input())
s = input()

s = s.split(" ")

l = int(s[0])

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

ans = 0
for x in s:
    x = int(x)
    ans = (ans +l//x)

print(ans%mod)

Submission status: Accepted

Solution code:
from fractions import gcd

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

def lcm(a):
    l = 1
    for i in a:
        l = l*i // gcd(l,i)
    
    return l

l = lcm(a)
count = 0
for i in a:
    count += l // i

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
mod = 10**9+7

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


def main():
    N = I()
    A = LI()

    l = A[0]

    for i in range(1,N):
        l = l*A[i] // gcm(l,A[i])
        
    B = [0]*N
    for i in range(N):
        B[i] = l * pow(A[i],mod-2,mod)

    ans = 0
    for i in range(N):
        ans += B[i]

    print(ans%mod)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

n = int(input())
a = list(map(int, input().split()))
l = 1
for ai in a:
    l = lcm(l, ai)

ans = 0
mod = 10**9 + 7
for ai in a:
    ans += l // ai

print(ans % mod)

Submission status: Accepted

Solution code:

from fractions import gcd


MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
#%%
def modinv(x,mod):
    return pow(x,mod-2,mod)

B = []
for a in A:
    b = modinv(a,MOD)
    B.append(b)

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

ans = 0

cur = 1
for a in A:
    cur =  lcm(cur,a)
for b in B:
    ans += cur*b
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
# 最小公倍数
from fractions import gcd
from functools import reduce
def lcm (x, y):
    return (x * y) // gcd(x, y)

# 最小公倍数(リスト)
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

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

lcm_A = lcm_list(A)

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

print(ans % mod)

Submission status: Accepted

Solution code:
def main():
  ans = 0
  n = int(input())
  a = tuple(map(int, input().split()))
  ov = 10**9+7
  from fractions import gcd
  def lcm(a):
      x = a[0]
      ln = len(a)
      for i in range(1, ln):
          x = (x * a[i]) // gcd(x, a[i])
      return x
  l = lcm(a)
  for i in range(n):
    ans += l//a[i]
  print(ans%ov)
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
def gcd(a, b):
    while(b > 0):
        a = a%b
        c = b
        b = a
        a = c
    return a

n = int(input())
s = input()

s = s.split(" ")
# for i s:
#     x = int(input())
#     arr.append(x)

l = int(s[0])

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

ans = 0
for x in s:
    x = int(x)
    ans += l//x

print(ans%1000000007)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
n=int(input())
numbers=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=0
x=lcm_list(numbers)
for i in range(n):
    l+=(x//numbers[i])
print(l%(10**9+7))

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

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

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

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

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

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
def lcm(a,b):
  return a*b//gcd(a,b)
l=reduce(lcm,a)
mod=pow(10,9)+7
ans=0
for x in a:
  ans+=l//x
print(ans%mod)

Submission status: Accepted

Solution code:
from fractions import gcd

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

mod = 10 ** 9 + 7

l = 1
for i in a:
    l = i * l // gcd(i,l)

count = 0
for i in a:
    count += l // i

print(count%mod)

Submission status: Accepted

Solution code:

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

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

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

Submission status: Accepted

Solution code:
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
    #lcm = lcm * a[i] // math.gcd(lcm, a[i])
lcm %= MOD
for i in range(n):
    ans += lcm * pow(a[i] , MOD-2, MOD)
    ans %= MOD
print(ans)

Submission status: Accepted

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

MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = 1
for i in A:
    lcm = (lcm*i)//gcd(lcm,i)
lcm %= MOD
ans = 0
for i in A:
    ans += lcm*pow(i,MOD-2,MOD)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
def s():
  from sys import stdin
  read=stdin.buffer.readline
  n=int(read())
  l=list(map(int,read().split()))
  f=l[0]
  mod=10**9+7
  def gcd(s,d):
    return gcd(d,s%d) if d else s
  for i in l:
    f=i*f//gcd(i,f)
  ans=0
  for iu in l:
    ans+=(f*pow(iu,mod-2,mod))%mod
    ans%=mod
  print(ans)
  
if __name__=="__main__":s()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
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=pow(10,9)+7
ans=0
for x in a:
  ans+=lcm//x
print(ans%mod)

Submission status: Accepted

Solution code:
import fractions
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7

lcm=A[0]
for i in range(1,n):
  if lcm%A[i]!=0:
    lcm=lcm*A[i]//fractions.gcd(lcm,A[i])
lcm%=mod
ans=0
for i in range(n):
  ans=(ans+lcm*pow(A[i],mod-2,mod))%mod
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N=int(input())
A=list(map(int,input().split(' ')))
ans = 0
L = 1
def lcm(x,y):
    return x//gcd(x,y)*y
for a in A:
    newL = lcm(L,a)
    ans = ans*(newL//L) + newL//a
    L = newL
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def s():
  from sys import stdin
  read=stdin.buffer.readline
  n=int(read())
  l=list(map(int,read().split()))
  f=l[0]
  mod=10**9+7
  def gcd(s,d):
    s,d=max(s,d),min(s,d)
    while  d:
      s,d=d,s%d
    return s
  for i in l:
    f=i*f//gcd(i,f)
  ans=0
  for iu in l:
    ans+=(f*pow(iu,mod-2,mod))%mod
    ans%=mod
  print(ans)
  
if __name__=="__main__":s()

Submission status: Accepted

Solution code:
from fractions import gcd
mod = 10**9+7
def lcm(a,b):
  return a*b//gcd(a,b)
def inv(a):
  return pow(a,mod-2,mod)
n = int(input())
a = list(map(int,input().split()))
f = [inv(a[i]) for i in range(n)]
x = 1
for i in range(n):
  x = lcm(x,a[i])
print(x%mod*sum(f)%mod)

Submission status: Accepted

Solution code:
def main():
  from functools import reduce
  from fractions import gcd
  ans = 0
  n = int(input())
  b = tuple(map(int, input().split()))
  ov = 10**9+7
  def lcm(x,y):
    return (x * y) // gcd(x, y)
  def lcm_list(a):
    return reduce(lcm, a, 1)
  l = lcm_list(b)
  for i in range(n):
    ans += l//b[i]
  print(ans%ov)
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys
import math
import heapq
import fractions

sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()

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

INL=LI()
LCM={}
for i in INL:
    for p in primes:
        cnt = 0
        while i%p == 0:
            i //= p
            cnt += 1
        if not p in LCM: LCM[p] = 0
        LCM[p] = max(LCM[p], cnt)
    if i != 1:
        if not i in LCM: LCM[i] = 0
        LCM[i] = max(LCM[i], 1)

res = 0
LCMMOD = 1
for p, cnt in LCM.items():
    LCMMOD *= (p**cnt)
    LCMMOD %= DVSR

for i in INL:
    res += LCMMOD*INV(i)%DVSR

print(res%DVSR)

Submission status: Accepted

Solution code:
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

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

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

a.sort()

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(n,m):
  if n>m:
    return gcd(m,n);
  if n==0:
    return m;
  return gcd(m-n*(m//n),n)
 
def lcm(x, y):
    return (x * y) // gcd(x, y)
  
n=int(input())
a=list(map(int,input().split()))
s=1
for i in a:
  s=lcm(s,i)
ans=0
for i in a:
  ans+=s//i
print(ans % 1000000007)

Submission status: Accepted

Solution code:
import math
import fractions
n = int(input())


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

lc = 1

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


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

print(ans%1000000007)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
l = 1
for i in a:
    l = i * l // (gcd(i, l))

cnt = 0
for i in a:
    cnt += l // i
print(cnt % mod)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))


# 素因数分解
def prime_factorization(n):
    fact=[]
    fact=defaultdict(int)
    for i in range(2, int(sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            # fact.append(i)
            fact[i]+=1
            # print(n,i)
    if n!=1:
        fact[n]+=1
    return fact
def main():
    N=I()
    A=LI()

    lcm = defaultdict(int)
    for a in A:
        p = prime_factorization(a)
        for k in p.keys():
            lcm[k] = max(p[k],lcm[k])
    L = ModInt(1)
    for l,v in lcm.items():
        L *= l**v
    ans = ModInt(0)
    for a in A:
        ans += L/a
    print(ans)
    
if __name__ == '__main__':
    main()

# #
# # 　　  ⋀_⋀　 
# #　　  (･ω･)  
# # .／ Ｕ ∽ Ｕ＼
# #  │＊　合　＊│
# #  │＊　格　＊│ 
# #  │＊　祈　＊│ 
# #  │＊　願　＊│ 
# #  │＊　　　＊│ 
# #      ￣
# #
# import sys
# sys.setrecursionlimit(10**6)
# input=sys.stdin.readline
# # from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
# # from heapq import heappop, heappush, heappushpop
# # from collections import Counter,defaultdict,deque
# # from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# # from bisect import bisect_left,bisect_right
# # from copy import deepcopy
# from fractions import gcd
# inf=float('inf')
# mod = 10**9+7
# def pprint(*A): 
#     for a in A:     print(*a,sep='\n')
# def INT_(n): return int(n)-1
# def MI(): return map(int,input().split())
# def MF(): return map(float, input().split())
# def MI_(): return map(INT_,input().split())
# def LI(): return list(MI())
# def LI_(): return [int(x) - 1 for x in input().split()]
# def LF(): return list(MF())
# def LIN(n:int): return [I() for _ in range(n)]
# def LLIN(n: int): return [LI() for _ in range(n)]
# def LLIN_(n: int): return [LI_() for _ in range(n)]
# def LLI(): return [list(map(int, l.split() )) for l in input()]
# def I(): return int(input())
# def F(): return float(input())
# def ST(): return input().replace('\n', '')
# #mint
# class ModInt:
#     def __init__(self, x):
#         self.x = x % mod
    
#     def __str__(self):
#         return str(self.x)
    
#     __repr__ = __str__

#     def __add__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(self.x + other.x)
#         else:
#             return ModInt(self.x + other)

#     __radd__ = __add__
        
#     def __sub__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(self.x - other.x)
#         else:
#             return ModInt(self.x - other)

#     def __rsub__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(other.x - self.x)
#         else:
#             return ModInt(other - self.x)

#     def __mul__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(self.x * other.x)
#         else:
#             return ModInt(self.x * other)

#     __rmul__ = __mul__

#     def __truediv__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(self.x * pow(other.x, mod-2,mod))
#         else:
#             return ModInt(self.x * pow(other, mod - 2, mod))
            
#     def __rtruediv(self, other):
#         if isinstance(other, self):
#             return ModInt(other * pow(self.x, mod - 2, mod))
#         else:
#             return ModInt(other.x * pow(self.x, mod - 2, mod))
            

#     def __pow__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(pow(self.x, other.x, mod))
#         else:
#             return ModInt(pow(self.x, other, mod))
            

#     def __rpow__(self, other):
#         if isinstance(other, ModInt):
#             return ModInt(pow(other.x, self.x, mod))
#         else:
#             return ModInt(pow(other, self.x, mod))

# def main():
#     N=I()
#     A=LI()
#     l = 1
#     for a in A:
#         l *= a//gcd(l,a)
#     ans = 0
#     l = ModInt(l)
#     for a in A:
#         ans += l/a
#     print(ans)
# if __name__ == '__main__':
#     main()

Submission status: Accepted

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

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


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

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

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

print(ans % mod)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 21:14:43 2020

@author: masat
"""
import fractions

N = int(input())

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

GCD = A_list[0]
LCM = A_list[0]
for i in A_list:
    GCD = fractions.gcd(LCM,i)
    LCM = (LCM*i)//GCD
    #print("{},{}".format(GCD, LCM))

answer = 0

for i in A_list:
    answer += LCM//i

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

Submission status: Accepted

Solution code:
from fractions import gcd
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)

ans = 0
for a in A:
    ans += lcm // a
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
mod = int(1e9 + 7)

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

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

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

def mod_lcm(a, b):
    return a * b % mod * inv(gcd(a, b)) % mod


while True:
    try:
        n = int(input())
        a = list(map(int, input().split()))
    except:
        break

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

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

Submission status: Accepted

Solution code:
from fractions import*
from functools import*
M=10**9+7
_,a=open(0)
*a,=map(int,a.split())
s=reduce(lambda x,y:x//gcd(x,y)*y,a)%M
c=0
for i in a:
    c+=s*pow(i,M-2,M)
    c%=M
print(c)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
MOD = 10**9+7
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

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

n = int(input())
aa = list(map(int,input().split()))
           
l = lcm(*aa)        
ans = 0
for ai in aa:
  ans += l//ai

print(ans % MOD)

Submission status: Accepted

Solution code:
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

N=int(input())
A=list(map(int, input().split()))
L = 1
for a in A:
    L = lcm(L, a)

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

MOD = 1000000007
print(int(ans)%MOD)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
import fractions



def main():
    N = int(input())
    A = tuple([int(x) for x in input().split()])
    MOD = 10 ** 9 + 7

    x = 1
    for a in A:
        x = (a * x) // fractions.gcd(a, x)

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

    print(ans % MOD)



    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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 = tuple(map(int,input().split(" ")))
ans = 0
mod = 10**9+7
l = 1
for i in range(N):
    l = lcm(l,A[i])
l %= mod

for i in A:
    ans += l*pow(i,mod-2,mod)
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import fractions
 
mod = 10**9+7
 
n = int(input())
a = list(map(int, input().split()))
 
div = a[0]
for i in a[1:]:
    div = div*i//fractions.gcd(div, i)

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

print(ans%mod)

Submission status: Accepted

Solution code:
N = input()

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

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

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

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

print(ans%1000000007)

Submission status: Accepted

Solution code:
import sys
import math
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd


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


def lcm(arr, mod = 10 ** 9 + 7):
    ret = 1
    for a in arr:
        ret = ret * a // gcd(ret, a)
    return ret

mod = 10 ** 9 + 7

N = int(input())
A = [int(x) for x in input().split()]
a = lcm(A)
print(sum(a // x for x in A) % mod)

Submission status: Accepted

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

l = reduce(lcm, A)

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

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

Submission status: Accepted

Solution code:

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

# from math import gcd # Python versions 3.5 and above
from functools import reduce # Python version 3.x


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

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

# def lcm(denominators):
#     return reduce(lambda a,b: a*b // gcd(a,b), denominators)

res = reduce(lcm, A, 1)
# res = lcm(A)
print(sum(res // A[i] for i in range(N)) % (10 ** 9 + 7))

Submission status: Accepted

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

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

ans = 0
for a in A:
    ans += lcm // a
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
MOD = 1000000007

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

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

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

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)
    ans %= MOD

print(ans)