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:
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)

def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

def lcm_core(a,b):
    g = gcd_core(a,b)
    return (a*b)//g

def lcm(arr):
    l = lcm_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        l = lcm_core(l,arr[i])
    return l

mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lc = lcm(A)
point =0
for i in A:
    point += lc/i
print(point%mod)

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
from functools import reduce
stdin = sys.stdin
         
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
     
INF=10**18
mod=10**9+7
N=int(input())
A=nl()
ans=0
min_bai=1
for i in range(N):#最大公倍数
    min_bai=min_bai*A[i]//fractions.gcd(min_bai,A[i])

lcm = reduce(lambda x,y: x//gcd(x,y)*y, A)
 
for i in range(N):
    ans+=lcm//A[i]


print(ans%mod)

Submission status: Runtime Error

Solution code:
import sys
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

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

MOD = 10**9+7
n = int(input())
n, *a = map(int, sys.stdin.buffer.read().split())
l = a[0]
for x in a[1:]:
    l = lcm(x, l)

l %= MOD

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

Submission status: Runtime Error

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

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

MOD = 10**9+7
n, *a = map(int, sys.stdin.buffer.read().split())
l = a[0]
for x in a[1:]:
    l = lcm(x, l)
l %= MOD

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

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions
n=int(input())
a=list(map(int,input().split()))
crossa=int(np.prod(a))
a_val=sum([crossa//i for i in a])
res=a_val // fractions.gcd(a_val,crossa)
print(res % 1000000007)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
a = [int(i) for i in input().split()]
sm = 1
g = 0
for i in a:
    sm *= i
    g = gcd(g, i)
ans = 0
lcm = sm // g
for i in a:
    ans += (lcm // a) % 100000007
print(ans % 100000007)

Submission status: Runtime Error

Solution code:
MOD = 1000000007
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)
ans=0
l=1
N =int(input())
a=list(map(int,input().split()))
for i in range(N):
    l = lcm(l,a[i])
for i in range(N):
    ans += l/a[i]
print(int(ans%MOD))

Submission status: Runtime Error

Solution code:
import math
MOD = 1000000007
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
ans=0
l=1
N =int(input())
a=list(map(int,input().split()))
for y in a:
    l = lcm(l,y)
for y in a:
    ans += l/y
print(ans%MOD)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
b = input().split(" ")
for i in b:
    a.append(int(i))

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

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

lcd = 1

for i in a:
    lcd = lca(lcd, i)

ans = 0

for i in a:
    ans += lcd/i

print(int(ans%(1e9+7)))

Submission status: Runtime Error

Solution code:
inf = 10**18
mod = 10**9+7

N = 10**6+1
inv_t = [0]+[1]

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

def moddiv(a, b):
    return a*inv_t[b]%mod

n = int(input())
a = list(map(int, input().split()))
tmp = 1
for num in a:
    f = math.gcd(tmp,num)
    tmp = tmp*num%mod
    tmp = moddiv(tmp, f)
ans = 0
for num in a:
    ans += moddiv(tmp, num)
    ans %= mod

print(ans)

Submission status: Runtime Error

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

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

mod = int(1e9+7)

n = int(input())
vs = map(int, input().split())
l = 1
for x in vs:
    l = lcm(l, x)

ans = 0
for x in vs:
    ans = (ans + ((l/x)%mod))%mod
print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
ans=1
gcd=A[0]
for i in range(1,N):
    a=A[i]
    b=math.gcd(a,gcd)
    temp=gcd
    gcd=temp*a//b
    ans=ans*(a//b)+temp//b
    ans%=MOD
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
mod = 10**9 + 7
n, *A = map(int, open(0).read().split())
if len(A) == 1:
    print(1)
else:
	l = reduce(lambda x, y: x*y // gcd(x, y), A) % mod
    s = 0
    for a in A:
        s += l * pow(a, mod-2, mod)
        s %= mod
    print(s)

Submission status: Runtime Error

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

l = reduce(lambda x, y: x*y // gcd(x, y)) % mod
s = 0
for a in A:
    s += l * pow(a, mod-2, mod)
    s %= mod
print(s)

Submission status: Runtime Error

Solution code:
from math import gcd

def factorization(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            e[i] = max(e[i], cnt)

    if n != 1:
        e[n] = max(e[n], 1)


def mod_pow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


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

mod = 10 ** 9 + 7
e = [0] * 10 ** 6

for v in a:
    factorization(v)

lcm = 1
for i, c in enumerate(e):
    if c > 0:
        lcm = lcm * mod_pow(i, c) % mod

res = 0
for v in a:
    res = (res + lcm * mod_pow(v, mod - 2)) % mod

print(res)

Submission status: Runtime Error

Solution code:
#E
def Primefact(n):
    Dic={}
    for i in range(2,int(pow(n,0.5))+1):
        if n%i==0:
            Dic[i]=0
            while True:
                n/=i
                Dic[i]+=1
                if n%i!=0:
                    break
        if n==1:
            break
    if n!=1:
        Dic[int(n)]=1
    return Dic

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

Prime={}
for i in range(N):
    D=Primefact(A[i])
    for key,v in D.items():
        if key in list(Prime.keys()):
            Prime[key]=max(Prime[key],v)
        else:
            Prime[key]=v
ans=0
for i in range(N):
    B=1
    D=Primefact(A[i])
    for key,v in Prime.items():
        if key in list(D.keys()):
            v-=D[key]
        B*=key**v
        B%=mod
    ans+=B
    ans%=mod
print(ans)

Submission status: Runtime Error

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

def main():
    num = int(input())
    d = list(map(int, input().split()))
    k = 1
    MOD = 1000000007
    ans = 0
    for a in d:
        k = lcm(k, a)
    for a in d:
        ans += k // a % MOD
    print(ans % MOD)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

b = [0]*n
for i in range(n):
    b[i] = lcm/a[i]

print(int(sum(b)) % (10**9+7))

Submission status: Runtime Error

Solution code:
from math import gcd,sqrt
from collections import defaultdict
from copy import deepcopy

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

p = [1]*(1001)
P = []  #1000までの素数表
p[0] = p[1] = 0
for x in range(2, int(sqrt(1000000))+1):
    if p[x]:
        P.append(x)
        for y in range(x*x, 1001, x):
            p[y] = 0

B = [defaultdict(int) for i in range(N)]  #N個の数を素因数分解したもの
lcm = defaultdict(int)  #N個の数のlcmを素因数分解したもの

for i in range(N):
    for j in P:
        if A[i] % j == 0:
            while A[i] % j == 0:
                A[i] //= j
                B[i][j] += 1
        lcm[j] = max(lcm[j],B[i][j])
    if A[i] != 1:
        B[i][A[i]] = 1
        lcm[A[i]] = 1

l = 1  #N個の数のlcm
for i in lcm.keys():
    l = (l*pow(i,lcm[i],mod)) % mod

ans = 0
#l/A[i]の和を求めていく
for i in range(N):
    r = l
    for j in list(B[i].keys()):
        r = (r*pow(j,mod-B[i][j]-1,mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from math import gcd
from functools import reduce
input = lambda: sys.stdin.readline().strip()
MOD = 1000000007
def lcm(a, b):
    return a // gcd(a, b) * b
n = int(input())
A = [int(x) for x in input().split()]
x = reduce(lcm, A)
print(sum(x // ai for ai in A) % MOD)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline().strip()
from math import gcd

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

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    x = 1
    for ai in A:
        x = lcm(x, ai)
    ans = 0
    for ai in A:
        ans += x // ai
        ans %= MOD
    print(ans)

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:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline().strip()
from math import gcd
from functools import reduce

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

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    x = reduce(lcm, A)
    ans = 0
    for ai in A:
        ans += x // ai
        ans %= MOD
    print(ans)

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:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline().strip()
from math import gcd
from functools import reduce

MOD = 1000000007  # type: int

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

def solve(N: int, A: "List[int]"):
    factors = [0 for i in range(10**6 + 1)]
    for x in A:
        i = 2
        while i * i <= x:
            curr = 0
            while x % i == 0:
                curr += 1
                x //= i
            factors[i] = max(factors[i], curr)
            i += 1
        if x > 1:
            factors[x] = max(factors[x], 1)
    lcm = 1
    for i in range(10**6 + 1):
        lcm *= pow(i, factors[i], MOD)
        lcm %= MOD
    ans = 0
    for ai in A:
        ans += lcm * modinv(ai) % MOD
        ans %= MOD
    print(ans)

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 functools
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
    return functools.reduce(multiple, nums)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7
    # 方針1.dp[k] := A1~Akまでについて条件を満たすようなB1~Bkの総和..?
    # 方針2.A全体のlcmをxとすると、ans=Σ(i=[0,N])x/Ai
    ans = 0
    x = lcm(A)
    for a in A:
        ans += int(x/a)%MOD
        ans %= MOD
    print(ans)

main()

Submission status: Runtime Error

Solution code:
import functools
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
    return functools.reduce(multiple, nums)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7
    # 方針1.dp[k] := A1~Akまでについて条件を満たすようなB1~Bkの総和..?
    # 方針2.A全体のgcdをxとすると、ans=Σ(i=[0,N])x/Ai
    ans = 0
    x = lcm(A)
    for a in A:
        ans += int(x/a)%MOD
        ans %= MOD
    print(ans)

main()

Submission status: Runtime Error

Solution code:
from fractions import gcd
import sys

input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception("modular inverse does not exist")
    else:
        return x % m


n = int(input())
if n == 1:
    print(1)
    exit()
A = list(map(int, input().split()))
lcm = A[0]
for i in range(n):
    g = gcd(lcm, A[i])
    lcm = lcm * A[i] // g
ans = 0
for i in range(n):
    gyaku = modinv(A[i])
    ans += lcm * gyaku
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

val = 1
for i in arr:
    val = lcm(val, i)

print(sum(val//i for i in arr))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

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

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

val = reduce(lcm, arr)

print(sum(val//i for i in arr))

Submission status: Runtime Error

Solution code:
import collections
n = int(raw_input())
elems = map(int, raw_input().split(' '))
def gcd( a, b ):
	return gcd(b, a % b)  if b else a

r = reduce( gcd, elems)
lcm = max([(a * b /r )for i,a in enumerate(elems) for j,b in enumerate(elems) if j!= i])

print sum([lcm/e for e in elems]) % ((10 ** 9) + 7)

Submission status: Runtime Error

Solution code:
from collections import Counter
from functools import reduce
from operator import mul

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    b = Counter(a)
    return b

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    fac = prime_factorize(A[0]) | prime_factorize(A[1])
    for x in A[2:]:
        fac |= prime_factorize(x)
    ans = 0
    f = [pow(x[0],x[1],100000007) for x in fac.items()]
    lcm = reduce(mul,f)
    for x in A:
        ans = (ans + (lcm // x)) % 1000000007
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from functools import reduce
from operator import mul

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    b = Counter(a)
    return b

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    fac = prime_factorize(A[0]) | prime_factorize(A[1])
    for x in A[2:]:
        fac |= prime_factorize(A[i])
    ans = 0
    f = [pow(x[0],x[1],100000007) for x in fac.items()]
    lcm = reduce(mul,f)
    for x in A:
        ans = (ans + (lcm // x)) % 1000000007
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict


def factorize(n: int) -> dict:
    f = defaultdict(int)
    while n % 2 == 0:
        f[2] += 1
        n //= 2
    p = 3
    while p * p <= n:
        while n % p == 0:
            f[p] += 1
            n //= p
        p += 2
    if n != 1:
        f[n] += 1
    return f


def _pow(b, p, mod):
    ret = 1
    while p:
        if p % 2 == 1:
            ret *= b
            ret %= mod
        b **= 2
        p //= 2
    return ret


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

a_fac = []
lcm_fac = defaultdict(int)
for a_i in a:
    a_fac_i = factorize(a[i])
    a_fac.append(a_fac_i)
    for k, v in a_fac_i.items():
        lcm_fac[k] = max(lcm_fac[k], v)

# print(lcm_fac)
ans = 0
for a_fac_i in a_fac:
    b_i = 1
    for k, v in lcm_fac.items():
        b_i *= _pow(k, v - a_fac_i[k], MOD)
        b_i %= MOD
    # print(i, a[i], b_i)
    ans += b_i
    ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

import fractions

G = A[0]
for i in range(N):
    G = G * A[i] // fractions.gcd(G, A[i])

ans = 0
for j in range(N):
    ans += G / A[j]

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

import fractions

G = A[0]
for i in range(N):
    G = G * A[i] // fractions.gcd(G, A[i])

ans = 0
for j in range(N):
    ans += G / A[j]

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

import math


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

ans = 0
for j in range(N):
    ans += gcd / A[j]

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

Submission status: Runtime Error

Solution code:
import math

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

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

ans = 0
for j in range(N):
    ans += gcd / A[j]

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

Submission status: Runtime Error

Solution code:
from math 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 * pow(a, MOD-2, MOD)
    ans %= MOD


print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
import fractions
def lcm(a):
    x = a[0]
    for i in range(1,len(a)):
        x = (x*a[i])//fractions.gcd(x,a[i])
        return x
A_lcm = lcm(A)
ans = 0
for i in A:
    ans += (A_lcm//i)%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
mod = 10**9+7
lcm = np.lcm.reduce(A)
for i in A:
    ans += (lcm//i)%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
import fractions
import functools

def multiple(a, b):
    return a*b // fractions.gcd(a, b)
def lcm(nums):
  return functools.reduce(multiple, nums)
 l[0]

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

Submission status: Runtime Error

Solution code:
from math import gcd,sqrt
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = []
for i in range(N):
    B.append(f(A[i]))

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd,sqrt
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    for i in range(2,int(sqrt(n))+1):
        if n % i == 0:
            r = 0
            while n % i == 0:
                n //= i
                r += 1
            d[i] = r
    if n != 1:
        d[n] = 1
    return d

B = []
for i in range(N):
    B.append(f(A[i]))

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = 100000007
Blist = Dict()
def culc(x,y):
    a0, b0 = 1, 0
    a1, b1 = 0, 1
    r0,r1 = x, y 
    q = 0
    while r1 > 0:
        q = r0 // r1
        r_tmp = r0 % r1
        r0, r1 = r1, r_tmp
        a_ = a0 - q * a1
        b_ = b0 - q * b1
        a0, a1 = a1, a_ #a2
        b0, b1 = b1, b_ #b2

    a0 = a0 % y
    if a0 < 0:
        a0 += x
    if b0 < 0:
        b0 += y
    
    return abs(a1), abs(b1)
  
for i in range(len(A)):
  for j in range(len(A)):
    Bi,Bj = culc(A[i],A[j])
    	if i not in Blist.keys():
        	Blist[i] = [Bi]
        else:
          	Blist[i].append(Bi)
        if j not in Blist.keys():
        	Blist[j] = [Bj]
        else:
          	Blist[j].append(Bj)
ret = 0
for k in Blist.values()
	tmp = 1
  	for n in k:
      tmp = tmp * n % M
    ret = (ret + tmp) % M
print(ret)

Submission status: Runtime Error

Solution code:
import math

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = LCM*A[i+1]//math.gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]= (LCM%MOD)*pow(A[i],MOD-2,MOD)%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i] + ans)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
import math

MOD = 1000000007
N = int(input())
A = list(map(int,input().split()))
print(math.gcd(5,4))

Submission status: Runtime Error

Solution code:
import math

MOD = 1000000007
N = int(input())
A = list(map(int,input().split()))
math.gcd(5,4)

Submission status: Runtime Error

Solution code:
import math

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = LCM*A[i+1]//math.gcd(A[i+1],LCM)

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
from math import gcd

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

Submission status: Runtime Error

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = LCM*A[i+1]//math.gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]=LCM//A[i]

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

print(ans)

Submission status: Runtime Error

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

LCM = A[0]
for i in range(0,N-1,1):
    #LCM = LCM*A[i+1]/math.gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = LCM*A[i+1]/math.gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = LCM*A[i+1]//math.gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = LCM*A[i+1]//gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

LCM = A[0]
for i in range(0,N-1,1):#O(nlogA)
    LCM = LCM*A[i+1]//gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):#O(n)
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
MOD = 1000000007

from math import gcd

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

LCM = A[0]
for i in range(0,N-1,1):#O(nlogA)
    LCM = LCM*A[i+1]//gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):#O(n)
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

mod = 10 ** 9 + 7

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

answer = 0
for x in a:
  answer = (answer + lcm // x) % mod
print(answer)

Submission status: Runtime Error

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 main():
    N = int(input())
    A = list(map(int, input().split()))
    L = np.lcm.reduce(A)
    ans = 0
    for a in A:
        ans += L // a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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_primes(upper_bound):
        from collections import deque
        target = deque(range(2,upper_bound+1))
        primes = []
        while target[0] <= upper_bound**0.5:
            top = target.popleft()
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
        
        return primes + list(target)


    N = II()
    A = LMIIS()

    primes = gen_primes(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                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

    # print(lcm)

    # from fractions import gcd
    # lcm = 1
    # for a in A:
    #     g = gcd(lcm,a)
    #     lcm = lcm * a * pow(g, MOD-2, MOD) % MOD
    # print(lcm)



    ans = 0
    # for i in range(N):
    #     t = 1
    #     for j in range(len(primes)):
    #         t = t*pow(primes[j],LCMP[j] - dp[i][j],MOD)%MOD
    #     ans = (ans + t) % MOD
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)




    

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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_primes(upper_bound):
        from collections import deque
        target = deque(range(2,upper_bound+1))
        primes = deque()
        while target[0] <= upper_bound**0.5:
            top = target.popleft()
            primes.append(top)
            tmp = deque()
            for num in target:
                if num % top != 0:
                    tmp.append(num)
            target = tmp
        return list(primes + target)


    N = II()
    A = LMIIS()
    primes = gen_primes(max(A))
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                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

    # print(lcm)

    # from fractions import gcd
    # lcm = 1
    # for a in A:
    #     g = gcd(lcm,a)
    #     lcm = lcm * a * pow(g, MOD-2, MOD) % MOD
    # print(lcm)



    ans = 0
    # for i in range(N):
    #     t = 1
    #     for j in range(len(primes)):
    #         t = t*pow(primes[j],LCMP[j] - dp[i][j],MOD)%MOD
    #     ans = (ans + t) % MOD
    for a in A:
        ans += lcm * pow(a, MOD-2, MOD)
        ans %= MOD
    print(ans)




    

if __name__ == '__main__':
    main()