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:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    # def gen_primes2(upper_bound):
    #     upper_bound += 1
    #     P = [True] * upper_bound
    #     P[0] = P[1] = False
    #     for i in range(4,upper_bound,2):
    #         P[i] = False
    #     for i in range(3,int(upper_bound**0.5),2):
    #         if P[i]:
    #             for j in range(i**2,upper_bound,i):
    #                 P[j] = False
    #     res = []
    #     for i in range(upper_bound):
    #         if P[i]:
    #             res.append(i)
    #     return res

    N = II()
    A = LMIIS()
    # upper_bound = max(A)
    # primes = gen_primes2(upper_bound)
    # LCMP = [0]*len(primes)
    # for i in range(N):
    #     # if i % 100 == 0:
    #     #     print(i)
    #     a = A[i]
    #     for j,p  in enumerate(primes):
    #         t = 0
    #         while a % p == 0:
    #             a //= p
    #             t += 1
    #         LCMP[j] = max(t, LCMP[j])
    #         if a == 1:
    #             break
    # lcm = 1
    # for i in range(len(primes)):
    #     lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD
    lcm = A[0]
    from fractions import gcd

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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


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


# mod m におけるaの逆元
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m

    # 負の場合は m を足して正の数にする
    if u < 0:
        u += m
    return u


def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = lcm_list(A)
    L %= MOD
    ans = 0
    for a in A:
        a_ = modinv(a, MOD)
        ans += L * a_ % MOD
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import fractions

from sys import stdin


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))
    sa = set(a)

    lcm = 1

    for ai in sa:
        lcm = (ai * lcm) // fractions.gcd(ai, lcm)

    ans = 0

    for ai in a:
        ans += lcm // ai
    ans %= 10 ** 9 + 7

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
l = 1
for x in a:
    l = l * x // gcd(l, x)
ans = sum(l // x for x in a) % MOD
print(ans)

Submission status: Accepted

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

def lcm(a,b):
  return a*b//gcd(a,b)
s=1
for i in A:
  s=lcm(s,i)
s%=MOD
ans=0
for i in A:
  ans+=s*pow(i,MOD-2,MOD)
  ans%=MOD
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    
    if temp != 1:
        arr.append([temp, 1])
    if not arr:
        arr.append([n, 1])
    
    return arr


def mod_div(x, y, mod=10 ** 9 + 7):
    return x * pow(y, mod - 2, mod) % mod


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    MOD = 10 ** 9 + 7
    
    max_exp = defaultdict(int)
    for ai in A:
        facts = factorization(ai)
        for fact, m in facts:
            if max_exp[fact] < m:
                max_exp[fact] = m
    
    lcm = 1
    for num, exp in max_exp.items():
        lcm = lcm * pow(num, exp, MOD) % MOD
    
    ans = sum([mod_div(lcm, ai) for ai in A]) % MOD
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def ti(): return tuple(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

from functools import reduce

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

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

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

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

def main():
    N = ii()
    A = ti()
    P = 10**9 + 7
    lcm_a = lcm_list(A) % P

    #逆元テーブルの作成
    N = 10**6+1
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

    ans = 0
    for num in A:
        ans = (ans + inv_t[num] * lcm_a) % P
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def ti(): return tuple(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

from functools import reduce

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

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

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

def main():
    N = ii()
    A = ti()
    P = 10**9 + 7
    lcm_a = lcm(A) % P

    N = 10**6+1
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

    #print(inv_t[:10])
    ans = 0
    for num in A:
        ans = (ans + inv_t[num] * lcm_a) % P
        #ans +=  (ans + lcm_a // num) % P
        #ans %= inf
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce, lru_cache

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

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

B = [1 for i in range(N)]
global_lcm = reduce(lcm, A) % MOD
ans = 0
for i in range(N):
    ans += (global_lcm*pow(A[i], MOD-2, MOD)) % MOD
    ans %= MOD

print(ans)

Submission status: Accepted

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

mod = 1000000007

l = 1

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

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

print(ans % mod)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

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

# lcm、逆元
MOD = 10 ** 9 + 7

N = ir()
A = np.array(lr())

U = 10 ** 6 + 10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p+p] = 0

M = 10 ** 3
small_primes = np.where(is_prime[:M])[0].tolist()

B = A.copy()
lcm = 1
for p in small_primes:
    e = 0
    while np.any(A%p == 0):
        e += 1
        A[A%p == 0] //= p
    lcm *= p ** e
    lcm %= MOD

for p in set(A.tolist()):
    lcm *= p
    lcm %= MOD

B = sum(pow(x, MOD-2, MOD) for x in B.tolist()) % MOD
B *= lcm
answer = B % MOD
print(answer % MOD)
# np.int64とint型の違いに注意

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    mod = 10**9 + 7

    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    # groupは要素1つでエラー

    # aの逆元を求める
    def inv(a, mod=mod):
        return pow(a, mod-2, mod)

    n = int(input())
    a = list(map(int, input().split()))
    if n == 1:
        print(1)
    else:
        l = lcm_group(a)
        res = 0
        for i in a:
            res += inv(i)
        print(res*l%mod)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

from fractions import gcd

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

p=10**9+7
n = 10 ** 6  # N は必要分だけ用意する
#fact = [1, 1]  # fact[n] = (n! mod p)
#factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用 逆元

for i in range(2, n + 1):
    #fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    #factinv.append((factinv[-1] * inv[-1]) % p)
#a//gcd(a,b)*b

def lcm(a,b):
    g=gcd(a,b)
    #return ((a*b)*pow(g,p-2,p))%p
    return a//gcd(a,b)*b

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



#print(LCM)
ans=0
LCM%=p
for i in range(N):
    ans+=(LCM*inv[A[i]])%p
    #ans+=(LCM*pow(A[i],p-2,p))%p
    ans%=p
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from fractions import gcd

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

p=10**9+7
n = 10 ** 6  # N は必要分だけ用意する
#fact = [1, 1]  # fact[n] = (n! mod p)
#factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用 逆元
"""
for i in range(2, n + 1):
    #fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    #factinv.append((factinv[-1] * inv[-1]) % p)
#a//gcd(a,b)*b
"""
def lcm(a,b):
    g=gcd(a,b)
    #return ((a*b)*pow(g,p-2,p))%p
    return a//gcd(a,b)*b

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



#print(LCM)
ans=0
LCM%=p
for i in range(N):
    #ans+=(LCM*inv[A[i]])%p
    ans+=(LCM*pow(A[i],p-2,p))%p
    ans%=p
print(ans)

Submission status: Accepted

Solution code:
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:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        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
    A_MX = 10 ** 6

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

    s = Sieve(n=A_MX)

    dict_lcm = defaultdict(int)
    for x in a:
        for prime, cnt in s.factor(x):
            dict_lcm[prime] = max(dict_lcm[prime], cnt)

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        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
    A_MX = 10 ** 6

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

    s = Sieve(n=A_MX)

    dict_lcm = defaultdict(int)
    for x in a:
        for prime, cnt in s.factor(x):
            dict_lcm[prime] = max(dict_lcm[prime], cnt)

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
# INF = float("inf")


# 最大公約数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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


def main():
    n = int(input())
    A = list(map(int, input().split()))
    l = 1
    for a in A:
        l = lcm(l, a)
    c = 0
    for a in A:
        c += pow(a, MOD - 2, MOD)
    ans = l * c % MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

ans = 0
for i in range(N):
  ans += pow(A[i],mod-2,mod)
  ans %= mod
print(kbs*ans%mod)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
from fractions import gcd
import numpy as np

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

MOD = 10 ** 9 + 7

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

A = np.array(A)
answer = (lcm // A).sum() % MOD
print(answer % MOD)
# np.int64とint型の違いに注意

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
def resolve():
    def lcm(X, Y):
        x = X
        y = Y
        if y > x:
            x, y = y, x
        while x % y != 0:
            x, y = y, x % y
        return X * Y // y
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = lcm(lsd, a[i])
    lsd = lsd % mod

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

    print(int(ans % mod))

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        '''
        pypyじゃないと地獄みたいな遅さなので注意
        '''
        self.mod = MOD
        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, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

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

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

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

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

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

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

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


def factorization(n: int):
    if n == 1:
        return []  # 1は素数ではない
    # 素因数分解
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):  # ここにバグがないか心配
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))

    if temp != 1:
        arr.append((temp, 1))

    if arr == []:
        arr.append((n, 1))

    return arr


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/abc152/tasks/abc152_e

N = read_a_int()
A = read_ints()
# AiBi=c (for any i )とすると、c=lcm(A)であるときsum(B)は最小となる
# cを求めてからc//Aiしていったものの総和が答え

# だけどlcmはとんでもでかくなるから因数分解形式での保持が必要
lcm = defaultdict(lambda: 0)
for a in A:
    a_fact = factorization(a)
    for k, v in a_fact:
        lcm[k] = max(lcm[k], v)

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

ans = ModInt(0)
for a in A:
    ans += c / a
print(ans)

Submission status: Accepted

Solution code:
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    while b:
        a, b = b, a % b
    return a

def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


def multi_lcm(array: list) -> int:
    ans = array[0]
    for i in range(1, len(array)):
        ans = (ans * array[i]) // gcd(ans, array[i])
    return ans


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

lcm_ = multi_lcm(a) % MOD
ans = 0
for i in range(n):
    ans += lcm_ * pow(a[i], MOD - 2, MOD) 
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    c = Counter(fct)
    return c

def solve(N,A):
    ans = 0
    mod = 10**9+7
    fcts = [0]*10**6
    for a in A:
        c = factorize(a)
        for k,v in c.items():
            fcts[k] = max(fcts[k],v)
    prod = 1
    for i,f in enumerate(fcts):
        if f==0:
            continue
        prod *= pow(i,f)
        prod %= mod
    for a in A:
        ans += prod*pow(a,mod-2,mod)
        ans %= mod
    return ans
print(solve(N,A))

Submission status: Accepted

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

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

LCM = 1
a_mod = 0
for i in range(n):
    LCM = lcm(LCM, a[i])
    a_mod = (a_mod + pow(a[i], mod - 2, mod)) % mod

LCM = LCM % mod
ans = LCM * a_mod
print(ans % mod)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
from collections import Counter
import math
N = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return Counter(fct)

fact_list = [dd(int) for _ in range(N)]
dic = dd(int)
for i,val in enumerate(a):
    tmp = factorize(val)
    for k,v in tmp.items():
        dic[k] = max(dic[k], v)

lcm = 1
for k,v in dic.items():
    lcm = (lcm*pow(k,v,MOD))%MOD
res = 0
for val in a:
    res = (res+pow(val, MOD-2, MOD))%MOD
res = (res*lcm)%MOD
print(res)

Submission status: Accepted

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

def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    mod=10**9+7
    l=1
    for i in range(N):
        l=lcm(l,A[i])

    res=0
    for i in range(N):
        res+=l//A[i]
    
    print(res%mod)
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
g = 0
lcm = 1
for x in a:
  g = gcd(lcm, x)
  lcm *= x // g
lcm %= mod
res = 0
for x in a:
  res += lcm * pow(x, mod - 2, mod) % mod
  res %= mod
print(res)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7


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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

from fractions import gcd

n, *a = map(int, read().split())
memo = 1
cnt = 0
mod = 10 ** 9 + 7
for aa in a:
    q = memo * aa // gcd(memo, aa)
    cnt *= q // memo
    memo = q
    cnt += q // aa
print(cnt % mod)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from collections import defaultdict


def main():
    mod = 1000000007                  # 10^9+7
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def lmi(): return list(map(int, input().split()))

    class Eratos:
        def __init__(self, num):
            self.table_max = num
            # self.table[i] は i が素数かどうかを示す (bool)
            self.table = [False if i == 0 or i == 1 else True for i in range(num+1)]
            for i in range(2, int(math.sqrt(num)) + 1):
                if self.table[i]:
                    for j in range(i ** 2, num + 1, i):    # i**2 からスタートすることで定数倍高速化できる
                        self.table[j] = False
            # self.table_max 以下の素数を列挙したリスト
            self.prime_numbers = [2] if self.table_max >= 2 else []
            for i in range(3, self.table_max + 1, 2):
                if self.table[i]:
                    self.prime_numbers.append(i)
        
        def is_prime(self, num):
            if num > self.table_max:
                raise ValueError('Eratos.is_prime(): exceed table_max({}). got {}'.format(self.table_max, num))
            return self.table[num]
        
        def prime_factorize(self, num):
            if num > self.table_max:
                raise ValueError('Eratos.prime_factorize(): exceed table_max({}). got {}'.format(self.table_max, num))
            factorized_dict = defaultdict(int)    # 素因数分解の結果を記録する辞書
            candidate_prime_numbers = [i for i in range(2, int(math.sqrt(num)) + 1) if self.is_prime(i)]
            # n について、√n 以下の素数で割り続けると最後には 1 or 素数となる
            # 背理法を考えれば自明 (残された数が √n より上の素数の積であると仮定。これは自明に n を超えるため矛盾)
            for p in candidate_prime_numbers:
                # これ以上調査は無意味
                if num == 1:
                    break
                while num % p == 0:
                    num //= p
                    factorized_dict[p] += 1
            if num != 1:
                factorized_dict[num] = 1
            return factorized_dict

    # import time
    # s = time.time()

    n = ii()
    L = lmi()
    a_max = max(L)
    # O(AlglgA) で前処理
    eratos = Eratos(a_max)
    # print('preprocessed (Eratostenes)')
    # print(time.time() - s)

    # O(n) * O(√A) で LCM を素因数分解した形で保存する
    lcm_dict = eratos.prime_factorize(L[0])
    for i in range(1, n):
        d = eratos.prime_factorize(L[i])
        for k, v in d.items():
            lcm_dict[k] = max(lcm_dict[k], v)
    # print('prime factorized')
    # print(time.time() - s)
    
    # O(√A)
    lcm_mod = 1
    for k, v in lcm_dict.items():
        lcm_mod = (lcm_mod * pow(k, v, mod)) % mod
    
    # O(n)
    ans = 0
    for a in L:
        # a^p-2 ≡ 1/a
        inverse_element = pow(a, mod-2, mod)
        ans = (ans + lcm_mod * inverse_element) % mod
    
    print(ans)
    # print(time.time() - s)

    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

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

Submission status: Accepted

Solution code:
MOD=10**9+7
def factorization(n):
    arr=[]
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    if(not arr):
        arr.append([1,1])
    if(tmp!=1):
        arr.append([tmp,1])
    return arr
def moddiv(a,m):
    return pow(a,m-2,m)
N=int(input())
A=list(map(int,input().split()))
cnt={}
for i in range(N):
    arr=factorization(A[i])
    for a,b in arr:
        cnt[a]=max(cnt.get(a,0),b)
g=1;res=0
for k,v in cnt.items():
    g=g*(pow(k,v,MOD))%MOD
for i in range(N):
    res=(res+(g*moddiv(A[i],MOD))%MOD)%MOD
print(res)