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: Runtime Error

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

b = [0]*N

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

Submission status: Runtime Error

Solution code:
import fractions
N = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,N):
	lcm = lcm*a[i]//math.fractions(lcm,a[i])

b = [0]*N

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

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,N):
	lcm = lcm*a[i]//math.gcd(lcm,a[i])

b = [0]*N

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return 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)

def calc_gcd_list(l):
    gcd = l[0]
    for i in range(1, N):
        gcd = gcd(gcd, l[i])
    return gcd

def calc_lcm_list(l):
    lcm = l[0]
    for i in range(1, N):
        lcm = lcm * l[i] // gcd(lcm, l[i])
    return lcm


N = input_one_number()
lstA = input_multiple_number_as_list()
lcm = calc_lcm_list(lstA)
pow = 10**9 +7
print(sum(lcm//a for a in lstA)%pow)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))



#複数の最小公倍数
def calc_lcm_list(l):
    lcm = l[0]
    for i in range(1, N):
        lcm = lcm * l[i] // fractions.gcd(lcm, l[i])
    return lcm


import fractions
N = input_one_number()
lstA = input_multiple_number_as_list()

gcd = calc_lcm_list(lstA)

ans = 0
for a in lstA:
    ans += (gcd // a)

print(ans %= 1000000007)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():

main()

Submission status: Runtime Error

Solution code:
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
ii = lambda: int(input())
lmis = lambda: list(mis())
N1097 = 10**9 + 7

def main():
    ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    ans = 0
    for a in A:
        ans += l//a
        ans %= N1097
    print(ans)


main()

Submission status: Runtime Error

Solution code:
import fractions


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


mod = 10 ** 9 + 7
n = int(input())
arr = list(map(int, input().split()))
g = arr[0]
for i in range(1, n):
    g = lcm(g, arr[i])

answer = 0
for i in range(n):
    answer += g / arr[i]

print(int(answer % mod))

Submission status: Runtime Error

Solution code:
import fractions


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


mod = 10 ** 9 + 7
n = int(input())
arr = list(map(int, input().split()))
g = arr[0]
for i in range(1, n):
    g = lcm(g, arr[i])

answer = 0
for i in arr:
    answer += g / i

print(int(answer % mod))

Submission status: Runtime Error

Solution code:
from math import gcd


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


def greatLCM(a):
    if len(a) < 2:
        return a[0]
    ans = lcm(a[0], a[1])
    p = 2
    while p < len(a):
        ans = lcm(ans, a[p])
        p += 1
    return ans


mod = 10 ** 9 + 7
n = int(input())
arr = list(map(int, input().split()))
g = greatLCM(arr)
answer = 0
for i in arr:
    answer += g / i

print(int(answer % mod))

Submission status: Runtime Error

Solution code:
from fractions import gcd


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


def greatLCM(a):
    if len(a) < 2:
        return a[0]
    ans = lcm(a[0], a[1])
    p = 2
    while p < len(a):
        ans = lcm(ans, a[p])
        p += 1
    return ans


mod = 10 ** 9 + 7
n = int(input())
arr = list(map(int, input().split()))
g = greatLCM(arr)
answer = 0
for i in arr:
    answer += g / i
    answer %= mod

print(int(answer))

Submission status: Runtime Error

Solution code:
from math import gcd


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


def greatLCM(a):
    ans = lcm(a[0], a[1])
    p = 2
    while p < len(a):
        ans = lcm(ans, a[p])
        p += 1
    return ans


n = int(input())
arr = list(map(int, input().split()))
g = greatLCM(arr)
answer = 0
for i in arr:
    answer += g / i
    answer %= 10 ** 9 + 7

print(int(answer))

Submission status: Runtime Error

Solution code:
from fractions import gcd


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


def greatLCM(a):
    ans = lcm(a[0], a[1])
    p = 2
    while p < len(a):
        ans = lcm(ans, a[p])
        p += 1
    return ans


n = int(input())
arr = list(map(int, input().split()))
g = greatLCM(arr)
answer = 0
for i in arr:
    answer += g / i
    answer %= 1e9 + 7

print(int(answer))

Submission status: Runtime Error

Solution code:
from math import gcd


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


def greatLCM(a):
    ans = lcm(a[0], a[1])
    p = 2
    while p < len(a):
        ans = lcm(ans, a[p])
        p += 1
    return ans


n = int(input())
arr = list(map(int, input().split()))
g = greatLCM(arr)
answer = 0
for i in arr:
    answer += g / i
    answer %= 1e9 + 7

print(int(answer))

Submission status: Runtime Error

Solution code:
N=int(input())
AN=list(map(int,input().split()))

lcdList=[]
for i in AN:
  lcdList.append(i)
lcdList=list(set(lcdList))

while len(lcdList)>1:
  defa=lcdList.pop(0)
  defb=lcdList.pop(0)
  a=defa
  b=defb
  if a<b:
    a,b=b,a
  while a%b!=0:
    a,b=b,a%b
  lcdList.append(defa*defb/b)
lcd=int(lcdList[0])

res=0
for i in AN:
  res+=lcd/i
  res%=(10**9+7)
  
print(int(res))

Submission status: Runtime Error

Solution code:
N=int(input())
AN=list(map(int,input().split()))

lcdList=[]
for i in AN:
  lcdList.append(i)

while len(lcdList)>1:
  defa=lcdList.pop(0)
  defb=lcdList.pop(0)
  a=defa
  b=defb
  if a<b:
    a,b=b,a
  while a%b!=0:
    a,b=b,a%b
  lcdList.append(defa*defb/b)
lcd=int(lcdList[0])

res=0
for i in AN:
  res+=int(lcd/i)
  res%=(10**9+7)
  
print(int(res))

Submission status: Runtime Error

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

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

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

s = 0
m = lcm(A)
for i in range(N):
    s += m / A[i]
print(int(s) % (10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions

n = int(input())
a = np.array(input().split(),dtype = int)

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

sum = 0
mod = 10**9+7
for i in a:
    sum += (l//a)%mod

print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(),dtype = int)

#素数の書き出し
pn = [2]
for i in range(3,10**3+100):
    for j in pn:
        if i%j == 0:
            break
        elif j == pn[-1]:
            pn.append(i)

#素因数分解
def pf(k):
    k_int = k
    p = [[],[]]
    i = 0
    times = 0
    while pn[i]*pn[i] <= k_int:
        if k%pn[i] == 0:
            times += 1
            k //= pn[i]
        else:
            if not times == 0:
                p[0].append(pn[i])
                p[1].append(times)
            i += 1
            times = 0
    if not k == 1:
        p[0].append(k)
        p[1].append(1)
    return p

#Aの素因数分解と最小公倍数の決定
a_pf = []
L = [[],[]]
for i in range(n):
    a_pf.append(pf(a[i]))
    for j in a_pf[i][0]:
        if j in L[0]:
            L[1][L[0].index(j)] = max([L[1][L[0].index(j)],a_pf[i][1][a_pf[i][0].index(j)]])
        else:
            L[0].append(j)
            L[1].append(a_pf[i][1][a_pf[i][0].index(j)])
'''
#Bの決定とその和
mod = 10**9+7
bsum = 0
for i in range(n):
    b = 1
    for j in L[0]:
        if j in a_pf[i][0]:
            b *= j**(L[1][L[0].index(j)]-a_pf[i][1][a_pf[i][0].index(j)])
        else:
            b *= j**L[1][L[0].index(j)]
        b %= mod
    bsum += b
    bsum %= mod
'''
print(bsum)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

n = int(input())
a = np.array(input().split(),dtype = int)

gcd = 1

for i in a:
    gcd = gcd//math.gcd(gcd,i)

ans = 0

ans += gcd//a

ans %= 10**9+7

print(ans)

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return tuple(map(int,input().split()))

def onem(): #Nとかの取得
    return int(input())


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

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

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

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

def main():
    n = onem()
    a = l()

    k = lcm_list(a[:n/2])
    kk = lcm_list(a[n/2:])
    k = lcm(k,kk)
    su = 0

    for i in range(n):
        su += k//a[i]
        
        su %= mod

    print(su)

if __name__ == "__main__":
    
    main()

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))

def onem(): #Nとかの取得
    return int(input())


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

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

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

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


if __name__ == "__main__":
    n = onem()
    a = l()

    k = lcm_list(a)

    su = 0

    for i in range(n):
        su += int(k/a[i])
        
        su %= mod

    print(su)

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))

def onem(): #Nとかの取得
    return int(input())


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

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

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

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


if __name__ == "__main__"
    n = onem()
    a = l()

    k = lcm_list(a)

    su = 0

    for i in range(n):
        su += k//a[i]
        su %= mod

    print(su)

Submission status: Runtime Error

Solution code:
import fractions

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

mod = 10**9+7

R = 1 # 最小公倍数
# 最小公倍数を求める
for A in A_list:
    R *= A // fractions.gcd(R, A)

# Bの合計を求める
ans = 0
for A in A_list:
    ans = ans + (R / A)

print(int(ans%(mod+7)))

Submission status: Runtime Error

Solution code:
import fractions

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

R = 1 # 最小公倍数
# 最小公倍数を求める
for A in A_list:
    R = R * A // fractions.gcd(R, A)

# Bの合計を求める
ans = 0
for A in A_list:
    ans = ans + (R / A)

print(int(ans%(pow(10,9)+7)))

Submission status: Runtime Error

Solution code:
import fractions

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

R = 1 # 最小公倍数
# 最小公倍数を求める
for A in A_list:
    R = R * A // fractions.gcd(R, A)

# Bの合計を求める
ans = 0
for A in A_list:
    ans = ans + (R / A)

print("%d"%(ans%(pow(10,9)+7)))

Submission status: Runtime Error

Solution code:
import math

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

R = 1 # 最小公倍数
# 最小公倍数を求める
for A in A_list:
    R = R * A // math.gcd(R, A)

# Bの合計を求める
ans = 0
for A in A_list:
    ans = ans + (R / A)

print("%d"%(ans%(pow(10,9)+7)))

Submission status: Runtime Error

Solution code:
import math
import fractions
N=int(input())
A=list(map(int,input().split()))
tmp=A[0]
ans=0

for i in range(N):
    tmp=math.floor((tmp*A[i])/(fractions.gcd(tmp,A[i])))

for i in range(N):
    ans+=(tmp/A[i])
    ans%=1000000007
    
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int,input().split()))
tmp=A[0]
ans=0

for i in range(N):
    tmp=math.floor((tmp*A[i])/(math.gcd(tmp,A[i])))

for i in range(N):
    ans+=(tmp/A[i])
    ans%=1000000007
    
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

mod=1000000007

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

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

lc= l[0]

for x in l:
	lc=lcm(lc,x)

ans=0
for x in l:
	ans+=int(lc/x)
	ans=ans%mod

print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))

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

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

_lcm = l[0]
for i in range(n):
    _lcm = lcm(_lcm, l[i])

ans = 0
for i in range(n):
    ans += (_lcm/l[i])%(10**9+7)
print(int(ans)%(10**9+7))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))

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

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

_lcm = l[0]
for i in range(n):
    _lcm = lcm(_lcm, l[i])

ans = 0
for i in range(n):
    ans += _lcm/l[i]
print(int(ans)%(10**9+7))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


def pow_mod(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= mod
        x *= x
        x %= mod
        n //= 2

    return K*x

#main関数
def main():
    """"ここに今までのコード"""

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

    plist = [0]*1000
    lcm = 1
    nokori=set()
    for a in A:
        for j in range(2, 1001):
            count_j=0
            while a % j == 0:
                count_j += 1
                a //= j
            plist[j-1]=max(plist[j-1],count_j)
        nokori |= {a}
    for x in nokori:
        lcm *= x
        lcm %= mod

    for i in range(1000):
        lcm *= pow_mod(i+1, plist[i], mod)
        lcm %= mod
    
    ans = 0

    for a in A:
        ans += lcm * pow_mod(a, mod-2, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log, gcd
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


def prime_decomposition(n):
    table = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            table += [i]
            n //= i
        if n == 1:
            break
    if n != 1:
        table += [a]
    return table


n = I()
A = LI()
prime_d = defaultdict(int)
for a in A:
    for p, cnt in Counter(prime_decomposition(a)).items():
         if prime_d[p] < cnt:
             prime_d[p] = cnt


lcm = 1
for p, cnt in prime_d.items():
    lcm = lcm * pow(p, cnt, mod) % mod


inv = list(range(10 ** 6 + 1))
for i in range(1, 10 ** 6 + 1):
    inv[i] = pow(inv[i], mod-2, mod)


ans = 0
for a in A:
    ans = ans + lcm * inv[a]


print(ans % mod)

Submission status: Runtime Error

Solution code:
# from math import gcd
from fraction import gcd

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

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import fractions
from functools import reduce
from copy import deepcopy
class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
2 3 4"""
        output = """13"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5
12 12 12 12 12"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3
1000000 999999 999998"""
        output = """996989508"""
        self.assertIO(input, output)

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

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

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

def resolve():
    N=int(input())
    A=map(int,input().split())
    B=deepcopy(A)
    lcm=lcm_list(A)
    B=[(lcm//i)%1000000007 for i in B]
    sm=0 

    for i in B:
        sm=(sm+i)%1000000007
    print(sm)

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
max_number = 10**6 + 5
pr = list(range(0, max_number))
def primes():
    npr = len(pr)
    for i, n in enumerate(pr):
        if n==1 or n==0:
            pr[i]=0
            continue
        if n:
            if n*n > max_number:
                break
            for j in range(i+n, npr,n):
                pr[j] = 0
    yield from [i for i in pr if i]


#ある素因数が何個含まれるか
def get_coef_num(a,prime):
    num = 0
    while True:
        if((a%prime)==0):
            a = a//prime
            num+=1
        else:
            break
    return num


N = int(input())
A = list(map(int, input().split()))
#B = A.copy()
pr_list = list(primes())
#print(f'#ofPR:{len(pr_list)}')
flag = False
coef_list = [0]*(len(pr_list))

for i,a in enumerate(A):
    for j,prime in enumerate(pr_list):
        flag = (pr[a]==a)
        if (a < (prime*prime)) and (not flag):
            break
        if a<pr:
            break
        if flag and a!=prime:
            continue
        temp = get_coef_num(a,prime)
        if coef_list[j]<temp :
            coef_list[j] = temp
#print(coef_list)

LCM = 1
for prime,num in zip(pr_list,coef_list):
    if num!=0:
        LCM*=(prime**num)
#print(LCM)

sum_B = 0
for a in A:
    #B[i] = (LCM//a)
    sum_B += (LCM//a)%(10**9+7)

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    ll N, A[10010], primeIndexList[10010], lcm = 1;
    map<ll, ll> maxIndex;

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    for (int i = 0; i < N; i++){
        ll now = A[i];
        //素因数分解
        for (ll j = 2; j*j <= A[i]; j++){
            if (now % j == 0){
                ll divCount = 0;
                while (now % j == 0){
                    now /= j;
                    divCount++;
                }
                maxIndex[j] = max(maxIndex[j], divCount);
            }
        }
        if (now != 1){
            maxIndex[now] = max(maxIndex[now], 1LL);
        }
    }

    //素因数分解の結果
    for (auto it : maxIndex){
        //cout << "FIRST : " << it.first << ", SECOND : " << it.second << endl;
    }

    ll ans = 0;
    for (int i = 0; i < N; i++){
        ll now = A[i];
        ll numAdd = 1;
        for (auto it : maxIndex){
            int divCount = 0;
            while (now % it.first == 0){
                now /= it.first;
                divCount++;
            }
            numAdd *= pow(it.first, it.second-divCount);
            numAdd %= MOD;
        }
        //cout << "numAdd = " << numAdd << endl;
        ans += numAdd;
        ans %= MOD;
    }
    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from math import gcd
from functools import reduce


MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    common_multi = reduce(lambda x, y: x * y // gcd(x, y), A)
    print(sum(map(lambda x: common_multi // x, A)) % MOD)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
lcm = np.lcm.reduce(A)
print(int(np.sum(1/A * lcm) % (1e9 + 7)))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<cstdint>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;

template<ll mod> class modint{
public:
  ll val=0;
  constexpr modint(ll x=0) noexcept : val(x%mod){
    while(x<0)x+=mod;
  }
  constexpr ll getmod(){return mod;}
  constexpr ll getvalue(){return val;}
  constexpr const ll &value() const noexcept {return val;}
  constexpr modint operator+(const modint &r) const noexcept{return modint(*this)+=r;}
  constexpr modint operator-(const modint &r) const noexcept{return modint(*this)-=r;}
  constexpr modint operator*(const modint &r) const noexcept{return modint(*this)*=r;}
  constexpr modint operator/(const modint &r) const noexcept{return modint(*this)/=r;}
  constexpr modint& operator+=(const modint &r) noexcept{
    val += r.val;
    if(val >= mod){
      val -= mod;
    }
    return *this;
  }
  constexpr modint& operator-=(const modint &r) noexcept{
    if(val < r.val){
      val += mod;
    }
    val -= r.val;
    return *this;
  }
  constexpr modint& operator*=(const modint &r) noexcept{
    val = val * r.val % mod;
    return *this;
  }
  constexpr modint& operator/=(const modint &r) noexcept{
    ll a=r.val,b=mod,u=1,v=0;
    while (b) {
      ll t = a/b;
      a -= t*b;swap(a,b);
      u -= t*v;swap(u,v);
    }
    val = val * u % mod;
    if(val < 0)val += mod;
    return *this;
  }
  constexpr bool operator == (const modint& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator < (const modint& r) const noexcept {
    return this->val < r.val;
  }
  constexpr bool operator != (const modint& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator << (ostream &os, const modint<mod>& x) noexcept {
    return os << x.val;
  }
  friend constexpr modint<mod> modpow(const modint<mod> &a,ll n) noexcept {
    if(n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if(n & 1) t = t * a;
    return t;
  }
};

using mint = modint<MOD>;

//n個の場合のlcmも2個で比べて順に適用していくだけ
signed main(){
  int n;cin >> n;
  vector<ll> a(n);for(int i=0;i<n;i++){cin >> a[i];}
  vector< map<mint,int> > prime_factors(n);
  for(int i=0;i<n;i++){
    for(int j=2;j<=1000;j++){
      while(a[i]%j==0){prime_factors[i][mint(j)]++;a[i]/=j;}
    }
    if(a[i]!=1) prime_factors[i][mint(a[i])]=1;
  }
  map<mint,int> lcm_all;
  for(ll i=0;i<n;i++){
    map<mint,int> now=prime_factors[i];
    for(auto& now_sub : now){
      lcm_all[now_sub.first]=max(now_sub.second,lcm_all[now_sub.first]);
    }
  }
  mint lcm_ans=mint(1);
  for(auto& lcm_all_sub : lcm_all){
    lcm_ans*=modpow(lcm_all_sub.first,lcm_all_sub.second);
  }
  mint cnt=0;
  for(int i=0;i<n;i++){
    mint cnt_sub=lcm_ans;
    map<mint,int> now=prime_factors[i];
    for(auto& now_sub : now){
      cnt_sub/=modpow(now_sub.first,now_sub.second);
    }
    cnt+=cnt_sub;
  }
  cout << cnt << endl;
}

Submission status: Runtime Error

Solution code:
#E - Flatten
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = [int(i) for i in input().split()]
from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return float(x)
A_lcm = lcm(A)
cnt = 0
for i in range(N):
    cnt += A_lcm/A[i]
print(int(cnt%(10**9+7)))

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(10000)

def lcm_pair(a, b):
    return int((a * b) // gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    if n == 1:
        return [1]
    elif n == 2:
        return a
    elif len(set(a)) == 1:
        return [1] * n
    else:
        b = [a[1]] + [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)] + [a[-2]]
        gcd_b = reduce(lambda x, y: gcd(x, y), b)
        b = [int(x // gcd_b) for x in b]
        c = lcm(list(map(lambda x, y: x * y, a, b)))
        b = [int(c // x) for x in a]
        gcd_b = reduce(lambda x, y: gcd(x, y), b)
        return [int(x // gcd_b) for x in b]

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

print(sum(solve(n, a)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

def lcm_pair(a, b):
    return int((a * b) // gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    if n == 1:
        return [1]
    elif n == 2:
        return a
    elif len(set(a)) == 1:
        return [1] * n
    else:
        b = [a[1]] + [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)] + [a[-2]]
        gcd_b = reduce(lambda x, y: gcd(x, y), b)
        b = [int(x // gcd_b) for x in b]
        c = lcm(list(map(lambda x, y: x * y, a, b)))
        return [int(c // x) for x in a]

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

print(sum(solve(n, a)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

def lcm_pair(a, b):
    return int((a * b) // gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    if n == 1:
        return [1]
    elif n == 2:
        return a
    elif len(set(a)) == 1:
        return [1] * n
    else:
        b = [a[1]] + [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)] + [a[-2]]
        gcd_b = reduce(lambda x, y: gcd(x, y), b)
        b = [int(x // gcd_b) for x in b]
        c = lcm(list(map(lambda x, y: x * y, a, b)))
        q = (10 ** 9 + 7)
        b = [int(c // x) % q for x in a]
        return sum(b) % q

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

print(solve(n, a))

Submission status: Runtime Error

Solution code:
#E - Flatten
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = [int(i) for i in input().split()]
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
A_lcm = lcm(A)
cnt = 0
for i in range(N):
    cnt += A_lcm/A[i]
print(int(cnt%(10**9+7)))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

def lcm_pair(a, b):
    return int((a * b) / gcd(a, b))

def lcm(nums):
    if len(nums) > 1:
        l = lcm_pair(nums[0], nums[1])
        return lcm([l] + nums[2:]) if len(nums) > 2 else l
    else:
        return nums[0]

def solve(n, a):
    if n == 1:
        return [1]
    elif n == 2:
        return a
    elif len(set(a)) == 1:
        return [1] * n
    else:
        b = [a[1]] + [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)] + [a[-2]]
        gcd_b = reduce(lambda x, y: gcd(x, y), b)
        b = [int(x / gcd_b) for x in b]
        c = lcm(list(map(lambda x, y: x * y, a, b)))
        return [int(c / x) for x in a]

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

print(sum(solve(n, a)) % (10 ** 9 + 7))