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 math
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N = int(input())
l = []
l = list(map(int, input().split()))

MODp = 1000000007
K = 1
for i in range(N):
  K = lcm(K,l[i])

Ans = 0
for i in range(N):
  Ans += ((K / l[i])%MODp)

Ans = Ans % MODp
print(Ans)

Submission status: Runtime Error

Solution code:
import math
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N = int(input())
l = []
l = list(map(int, input().split()))

MODp = 1000000007
K = 1
for i in range(N):
  K = math.lcm(K,l[i])

Ans = 0
for i in range(N):
  Ans += ((K / l[i])%MODp)

Ans = Ans % MODp
print(Ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
l = []
l = list(map(int, input().split()))

MODp = 1000000007
K = 1
for i in range(N):
  K = math.lcm(K,l[i])

Ans = 0
for i in range(N):
  Ans += ((K / l[i])%MODp)

Ans = Ans % MODp
print(Ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
l = []
for i in range(N):
  l = list(map(int, input().split()))

MODp = 1000000007
K = 1
for i in range(N):
  K = math.lcm(K,l[i])

Ans = 0
for i in range(N):
  Ans += ((K / l[i])%MODp)

Ans = Ans % MODp
print(Ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

mod = 10**9 + 7

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
n=int(input())
A=list(map(int,input().split()))
lc=reduce(lambda a,b: a*b//gcd(a,b),A)
b=[lc//i for i in A]
print(sum(b)%(1000*1000000+7))

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
n=int(input())
a=list(map(int,input().split()))
lc=reduce(lambda a,b: a*b//gcd(a,b),a)
b=[lc//i for i in a]
print(sum(b)%(1000*1000000+7))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

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

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

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



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

MOD = 10**9+7
lcm_val = lcm_list(A)
diff = [lcm_val // a for a in A]
print(sum(diff)%MOD)

Submission status: Runtime Error

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


# a**n(mod m)を返す
def pow_mod(a, n, m):
    tmp = 1
    a_power = a
    nn = n
    while 1:
        if nn%2:
            tmp = (tmp * a_power )% m
        a_power = (a_power * a_power)% m
        nn = nn // 2
        if nn == 0:
            break
    return tmp

# a**-1 (mod p) p must be prime
def inv_mod(a, p):
    return pow_mod(a, p-2, p)

# lcm(arr) mod p
def lcm_mod(arr, p):
    arr2 = [arr[0]]
    for i in range(1,len(arr)):
        res = arr[i]
        for a in arr2:
            res = res // gcd(res, a)
            if res == 1:
                break
        if res != 1:
            arr2 += [res]
    prod = 1
    for a in arr2:
        prod = prod*a % p
    return prod

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

lcm = lcm_mod(arr, b)

tmp = 0
for a in arr:
  tmp += (lcm * inv_mod(a,b))%b

print(tmp)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
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[i] = cnt

    if temp!=1:
        arr[temp] = 1

    if arr=={}:
        arr[n] = 1

    return arr

lcm_dict = {}
for a in A:
  a_dict = factorization(a)
  for key in a_dict.keys():
    if key not in lcm_dict.keys():
      lcm_dict[key] = a_dict[key]
    elif lcm_dict[key] < a_dict[key]:
      lcm_dict[key] = a_dict[key]
kake = 1
for key in lcm_dict.keys():
  kake *= lcm_dict[key] * key
print(int(sum([ kake / a  for a in A]) % (1e9+7)))

Submission status: Runtime Error

Solution code:

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

N = int(input())
a = []
gong = 1
a = list(map(int, input().split()))

for i in range(N):
    x = a[i]
    gong = gong * x / gcd(gong, x)
sum = 0
for i in range(N):
    sum = gong // a[i] + sum
Mod = 1000000007
sum = sum % Mod
print(int(sum))

Submission status: Runtime Error

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

def lcm(a,b):
    return (a*b)//gcd(a,b)
n = int(input())
mod = 1e9 + 7
a = [int(i) for i in input().split()]
ans = 1    
for i in a:
    ans = lcm(ans,i)

print(sum(ans//i for i in a)%mod)

Submission status: Runtime Error

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

def lcm(a,b):
    return (a*b)//gcd(a,b)
n = int(input())
mod = 1e9 + 7
a = [int(i) for i in input().split()]
ans = 1    
for i in a:
    ans = lcm(ans,i)

print("%d" %(sum(ans//i for i in a)%mod))

Submission status: Runtime Error

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

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

n = int(input())
b = [1]*(n+5)
mod = 1e9 + 7
a = [int(i) for i in input().split()]
    
for i in range(n):
    for j in range(i+1,n):
        x = a[i]
        y = a[j]
        m = gcd(x,y)
        x //= m
        y //= m
        b[i] = lcm(b[i],y)
        b[j] = lcm(b[j],x)
sum = 0
for i in range(n):
    sum += b[i]
print(int(sum%mod))

Submission status: Runtime Error

Solution code:
import math

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

n = int(input())
b = [1]*(n+5)
mod = 1e9 + 7
a = [int(i) for i in input().split()]
    
for i in range(n):
    for j in range(i+1,n):
        x = a[i]
        y = a[j]
        m = math.gcd(x,y)
        x //= m
        y //= m
        b[i] = lcm(b[i],y)
        b[j] = lcm(b[j],x)
sum = 0
for i in range(n):
    sum += b[i]
print(int(sum%mod))

Submission status: Runtime Error

Solution code:
import math

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

n = int(input())
b = [1]*(n+5)
mod = 1e9 + 7
a = [int(i) for i in input().split()]
    
for i in range(n):
    for j in range(i+1,n):
        x = a[i]
        y = a[j]
        m = math.gcd(x,y)
        x //= m
        y //= m
        b[i] = lcm(b[i],y)
        b[j] = lcm(b[j],x)
sum = 0
for i in range(n):
    sum += b[i]
print("%d" %(sum%mod))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
b = [1]*(n+1)
mod = 1e9 + 7
a = [int(i) for i in input().split()]
    
for i in range(n):
    for j in range(i+1,n):
        x = a[i];y = a[j];m = math.gcd(x,y);
        x //= m;y //= m;
        b[i] = int(b[i]*y)//int(math.gcd(b[i],y))
        b[j] = int(b[j]*x)//int(math.gcd(b[j],x))
sum = 0
for i in range(n):
    sum += b[i]
print("%d" %(sum%mod))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import lru_cache
sys.setrecursionlimit(10**9)

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

    lcm = np.lcm.reduce(A)
    _, ans = divmod(sum(map(lambda a: lcm // a ,A)), (10**9+7))

    print(ans)

if __name__ == "__main__":
  main()

Submission status: Runtime Error

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

mod = 1000000007
n = int(input())
arr = input()
a = list(map(int, arr.split(' ')))
lc = a[0]
res = 0
for i in range(n):
    lc = lcm(lc, a[i])
for i in range(n):
    res = res + 1//a[i]
print(ans % mod)

Submission status: Runtime Error

Solution code:
def gcd(a,b): 
      
    # Everything divides 0  
    if (b == 0): 
         return a 
    return gcd(b, a%b) 
  
def add(num1,num2,den1,den2):
    num=num1*den2+num2*den1 
    den=den1*den2 
    g=gcd(num,den)
    num//=g
    den//=g 
    return [num,den]
    
n=int(input())
a=[int(x) for x in input().split()]
y=a[0]
num,den=y,y
for i in range(1,len(a)):
    num,den=add(num,y,den,a[i])
print(num%(10**9+7))

Submission status: Runtime Error

Solution code:
from math import gcd
def add(num1,num2,den1,den2):
    num=num1*den2+num2*den1 
    den=den1*den2 
    g=gcd(num,den)
    num//=g
    den//=g 
    return [num,den]
    
n=int(input())
a=[int(x) for x in input().split()]
y=a[0]
num,den=y,y
for i in range(1,len(a)):
    num,den=add(num,y,den,a[i])
print(num%(10**9+7))

Submission status: Runtime Error

Solution code:
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

const int mod = 1e9 + 7;

int mpow(int a, int b) {
  if (b == 0) return 1;
  int nesf = mpow(a, b / 2);
  if (b % 2 == 0) {
    return nesf * nesf % mod;
  }
  return a * nesf % mod * nesf % mod;
}

const int N = 1e6 + 100;
int mx[N];

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int tmp = a[i];
    for (int j = 2; j * j <= tmp; j++) {
      if (tmp % j == 0) {
        int cnt = 0;
        while (tmp % j == 0) {
          cnt++, tmp /= j;
        }
        mx[j] = max(mx[j], cnt);
      }
    }
    if (tmp > 1) {
      mx[tmp] = max(mx[tmp], 1ll);
    }
  }
  int mul = 1;
  for (int i = 2; i < N; i++) {
    mul *= mpow(i, mx[i]);
    mul %= mod;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += mul * mpow(a[i], mod - 2) % mod;
    ans %= mod;
  }
  cout << ans << "\n";
}

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7

def mpow(a, b) :
    if b == 0:
        return 1
    nesf = mpow(a, b // 2)
    if b % 2 == 0:
        return nesf * nesf % mod
    return a * nesf * nesf % mod

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

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

n = int(input())
a = list(map(int, input().split()))
c = a
b = []

while len(c) > 1:
    if len(c) % 2 == 1:
        c.append(c[len(c) - 1])
    for i in range(0, len(c), 2):
        b.append(lcm(c[i], c[i + 1]))
    c = b
    b = []

mul = c[0] % mod

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

Submission status: Runtime Error

Solution code:
def get(text,n):
    ans = [""]*n
    i = 0
    for x in text:
        if x==" ":
            i = i + 1
        else:
            ans[i] = ans[i]+x
    return ans

import numpy as np

N = int(input())
a = get(input(),N)
for i in range(N):
    a[i] = int(a[i])

a2 = np.array(a)
g = np.lcm.reduce(a2)

r = 0
for i in range(N):
    r = r + (g//a[i])%(10**9+7)

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

Submission status: Runtime Error

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

"""
def input():
    return sys.stdin.readline()[:-1]
"""

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

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

	ans = reduce(lcm, A)
	"""
	a = 1
	for i in A:
		a = lcm(a, i)
	"""
	#print(a, ans)
	B = np.array([ans//i for i in A])
	print(np.sum(B) % mod)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from fractions import gcd
N = input()
A = list(map(int, input().split(" ")))
def lcm(x, y):
    return (x * y) // gcd(x, y)
tmp = 1
for i in A:
    tmp = lcm(tmp, i)
print(int(sum([tmp / i for i in A]) % (10**9 + 7)))

Submission status: Runtime Error

Solution code:
import numpy


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

lcm = 1
for a in A:
    lcm = numpy.lcm(lcm, a)
lcm %= MOD

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

print(ans)

Submission status: Runtime Error

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()))

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

l %= MOD

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

print(int(ans))

Submission status: Runtime Error

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

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

l %= MOD

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

print(int(ans))

Submission status: Runtime Error

Solution code:
#from fractions import gcd
from math import gcd
import numpy as np
#import sys
#input = sys.stdin.readline
mod = 10**9+7

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

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

ans = lcm*np.sum([pow(s,mod-2,mod) for s in A])%mod
#ans = sum([lcm//s % mod for s in A]) % mod

print(int(ans))

Submission status: Runtime Error

Solution code:
#from fractions import gcd
#from math import gcd
import numpy as np
#import math
#import sys
#input = sys.stdin.readline
mod = 10**9+7


def obtain_ps(n):
    ps = {}
    # while(n>1):
    n_input = n

    for i_tmp in range(2, int(n_input**0.5)+1):
        if not n % i_tmp == 0:
            continue
        i_tmp2 = n//i_tmp
        for i in [i_tmp, i_tmp2]:
            i_primary = True
            for j in range(2, int(i**0.5)+1):
                if i % j == 0:
                    i_primary = False
                    break
            if not i_primary:
                continue
            count = 1
            r = i
            while(not n % r):
                count += 1
                r *= i
            count -= 1
            ps[i] = count
            n = n/(i**count)
            if n == 1:
                break
    if n == n_input:
        ps[n] = 1
    return ps


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

ps = {}
ps_s = []
for s in A:
    ps_tmp = obtain_ps(s)
    ps_s.append(ps_tmp)
    for k, v in ps_tmp.items():
        if k in ps.keys():
            ps[k] = max(v, ps_tmp[k])
        else:
            ps[k] = v

ans = 0
for ps_tmp in ps_s:
    plus = 1
    for k, v in ps.items():
        if k in ps_tmp.keys():
            plus *= k**(v-ps_tmp[k]) % mod
        else:
            plus *= k**v % mod

    ans += plus % mod
#lcm=np.product([k**v for k,v in ps.items()])

#ans = np.sum([lcm // s %mod for s in A]) % mod

print(int(ans % mod))

Submission status: Runtime Error

Solution code:
#from fractions import gcd
#from math import gcd
import numpy as np
#import math
import sys
input = sys.stdin.readline
mod = 10**9+7


def obtain_ps(n):
    ps = {}
    # while(n>1):
    n_input = n

    for i_tmp in range(2, int(n_input**0.5)+1):
        if not n % i_tmp == 0:
            continue
        i_tmp2 = n//i_tmp
        for i in [i_tmp, i_tmp2]:
            i_primary = True
            for j in range(2, int(i**0.5)+1):
                if i % j == 0:
                    i_primary = False
                    break
            if not i_primary:
                continue
            count = 1
            r = i
            while(not n % r):
                count += 1
                r *= i
            count -= 1
            ps[i] = count
            n = n/(i**count)
            if n == 1:
                break
    if n == n_input:
        ps[n] = 1
    return ps


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

ps = {}
ps_s = []
for s in A:
    ps_tmp = obtain_ps(s)
    ps_s.append(ps_tmp)
    for k, v in ps_tmp.items():
        if k in ps.keys():
            ps[k] = max(v, ps_tmp[k])
        else:
            ps[k] = v

ans = 0
for ps_tmp in ps_s:
    plus = 1
    for k, v in ps.items():
        if k in ps_tmp.keys():
            plus *= k**(v-ps_tmp[k]) & mod
        else:
            plus *= k**v % mod

    ans += plus % mod
#lcm=np.product([k**v for k,v in ps.items()])

#ans = np.sum([lcm // s %mod for s in A]) % mod

print(int(ans % mod))

Submission status: Runtime Error

Solution code:
#from fractions import gcd
#from math import gcd
import numpy as np
#import math
#import sys
#input = sys.stdin.readline
mod = 10**9+7

def obtain_ps(n):
    ps={}
    #while(n>1):
    n_input=n

    for i_tmp in range(2, int(n_input**0.5)+1):
        if not n%i_tmp==0:
            continue
        for i in [i_tmp, n//i_tmp]:
            i_primary=True
            for j in range(2, int(i**0.5)+1):
                if i%j==0:
                    i_primary=False
                    break
            if not i_primary:
                continue
            count=1
            r=i
            while(not n%r):
                count +=1
                r*=i
            count-=1
            ps[i]=count
            n=n/(i**count)
            if n==1:
                break
    if n==n_input:
        ps[n]=1
    return ps

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

ps={}
ps_s=[]
for s in A:
    ps_tmp=obtain_ps(s)
    ps_s.append(ps_tmp)
    for k,v in ps_tmp.items():
        if k in ps.keys():
            ps[k]=max(v, ps_tmp[k])
        else:
            ps[k]=v

ans=0
for ps_tmp in ps_s:
    plus=1
    for k,v in ps.items():
        if k in ps_tmp.keys():
            plus*=k**(v-ps_tmp[k])
        else:
            plus*=k**v

    ans+=plus%mod
#lcm=np.product([k**v for k,v in ps.items()])

#ans = np.sum([lcm // s %mod for s in A]) % mod

print(int(ans%mod))

Submission status: Runtime Error

Solution code:
#from fractions import gcd
from math import gcd
#import numpy as np
#import sys
#input = sys.stdin.readline
mod = 10**9+7

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

lcms = [A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s) % mod) for s in A]
lcm = lcms[-1]

ans = np.sum([lcm*pow(s, mod-2, mod) % mod for s in A]) % mod

print(int(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd
#from math import gcd
#import numpy as np
import sys
input = sys.stdin.readline
mod=10**9+7

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

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
lcm=lcms[-1]

ans=np.sum([lcm*pow(s, mod-2, mod) %mod  for s in A]) % mod

print(int(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd
#from math import gcd
#import numpy as np

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

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]

ans=sum([(lcms[-1]//s) %(1e9+7) for s in A])%(10**9+7)

print(int(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd
#from math import gcd
#import numpy as np

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

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]

ans=sum([(lcms[-1]//s) %(1e9+7) for s in A])%(1e9+7)

print(int(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd
#from math import gcd
import numpy as np

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

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
ans=np.sum(([lcms[-1]//s for s in A]))%(1e9+7)

print(int(ans))

Submission status: Runtime Error

Solution code:
#from fractions import gcd
from math import gcd
import numpy as np

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

lcms=[A[0]]
[lcms.append(s*lcms[-1]//gcd(lcms[-1], s)) for s in A]
ans=np.sum(([lcms[-1]//s for s in A]))%(1e9+7)

print(int(ans))

Submission status: Runtime Error

Solution code:
import fractions
import sys

input = sys.stdin.readline

mp = 1000###max prime
mod = 10 ** 9 + 7
def prime_factorize(n):
    a = [0] * mp
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

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

def fact_mul(x,y):
    ret = [0] * mp
    for i in range(mp):
        ret[i] = x[i] + y[i]
    return ret

def fact_div(x,y):
    ret = [0] * mp
    for i in range(mp):
        ret[i] = x[i] - y[i]
    return ret

def cal_mod(x):
    ret = 1
    for i in range(mp):
        ret *= (i**x[i]) % mod
        ret %= mod
    return ret


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

A_fact = [0] * N###Aの各要素の素因数分解
for i in range(N):
    A_fact[i] = prime_factorize(A[i])
#print(A_fact[0][0:12])

l_fact = A_fact[0][:]

for i in range(1,N):
    for j in range(1,mp):
        l_fact[j] = max(A_fact[i][j],l_fact[j])

B0_fact = [0] * mp


for i in range(mp):
    B0_fact[i] = max(0,l_fact[i]-A_fact[0][i])

ans = cal_mod(B0_fact)
#print(A_fact[0][0:12])
#print(B0_fact[0:12])
#print(cal_mod(l_fact))
#print(ans)
#print(A_fact)
#print(B0_fact)
for i in range(1,N):
    Bi = fact_div(fact_mul(A_fact[0],B0_fact),A_fact[i])
    ans += cal_mod(Bi)
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import sys

input = sys.stdin.readline

mp = 1000###max prime
mod = 10 ** 9 + 7
def prime_factorize(n):
    a = [0] * mp
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

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

def fact_mul(x,y):
    ret = [0] * mp
    for i in range(mp):
        ret[i] = x[i] + y[i]
    return ret

def fact_div(x,y):
    ret = [0] * mp
    for i in range(mp):
        ret[i] = x[i] - y[i]
    return ret

def cal_mod(x):
    ret = 1
    for i in range(mp):
        ret *= (i**x[i]) % mod
        ret %= mod
    return ret


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


l = A[0]###A全体の最大公約数

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

B0_fact = [0] * mp
l_fact = prime_factorize(l)

A_fact = [0] * N
for i in range(N):
    A_fact[i] = prime_factorize(A[i])

for i in range(mp):
    B0_fact[i] = max(0,l_fact[i]-A_fact[0][i])

ans = cal_mod(B0_fact)

#print(A_fact)
#print(B0_fact)
for i in range(1,N):
    Bi = fact_div(fact_mul(A_fact[0],B0_fact),A_fact[i])
    ans += cal_mod(Bi)
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import collections

mp = 1000###max prime
mod = 10 ** 9 + 7
def prime_factorize(n):
    a = [0] * mp
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

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

def fact_mul(x,y):
    ret = [0] * mp
    for i in range(mp):
        ret[i] = x[i] + y[i]
    return ret

def fact_div(x,y):
    ret = [0] * mp
    for i in range(mp):
        ret[i] = x[i] - y[i]
    return ret

def cal_mod(x):
    ret = 1
    for i in range(mp):
        ret *= (i**x[i]) % mod
        ret %= mod
    return ret


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


l = A[0]###A全体の最大公約数

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

B0_fact = [0] * mp
l_fact = prime_factorize(l)

A_fact = [0] * N
for i in range(N):
    A_fact[i] = prime_factorize(A[i])

for i in range(mp):
    B0_fact[i] = max(0,l_fact[i]-A_fact[0][i])

ans = cal_mod(B0_fact)

#print(A_fact)
#print(B0_fact)
for i in range(1,N):
    Bi = fact_div(fact_mul(A_fact[0],B0_fact),A_fact[i])
    ans += cal_mod(Bi)
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
input = sys.stdin.buffer.readline
def lcm(x,y):
  return((x*y)//math.gcd(x,y))
def main():
  N=int(input())
  arr=list(map(int,input().split()))
  MOD=1000000007 
  LCM=1
  for i in arr:
    LCM=lcm(LCM,i)
  ans=0
  for i in arr:
    ans += LCM//i
  print(ans%MOD)
if __name__=="__main__":
  main()

Submission status: Runtime Error

Solution code:
def lcm(a, b):
  return abs(a*b) // math.gcd(a, b)
import math
n=input()
s=input()
arr=s.split()
nLcm=1
for i in arr:
  now=int(i)
  nLcm=lcm(now,nLcm)
ans=0
MOD=1000000007
for i in arr:
  now=int(i)
  delta=(nLcm/now)%MOD
  ans+=delta
  ans%=MOD
print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = np.array([int(c) for c in input().split()])
MOD = 10**9+7
U = 10**6+10
B = np.zeros(U)
B[2] = 1
B[3::2] = 1
for i in range(3,U):
  if i*i>U:
    break
  if B[i]:
    B[i*i::i+i] = 0
pls = np.where(B[:1000])[0].tolist()
B = A.copy()
lcm = 1
for p in pls:
  e = 0
  if np.any(A%p==0):
    A[A%p==0] //= p
    e += 1
  lcm *= p**e
  lcm %= MOD
for x in set(A.tolist()):
  lcm *= x
  lcm %= MOD
x = sum(pow(c, MOD-2, MOD) for c in B.tolist())
print(x*lcm%MOD)

Submission status: Runtime Error

Solution code:
def main():
  from sys import stdin
  from math import gcd
  n = int(stdin.readline())
  a = [int(z) for z in stdin.readline().split()]
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
  sm = 0
  for i in range(n):
    sm += lcm // a[i]
  print(sm)

main()

Submission status: Runtime Error

Solution code:
def main():
  from sys import *
  from math import gcd
  n = int(stdin.readline())
  a = [int(z) for z in stdin.readline().split()]
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] / gcd(lcm, a[i])
  sm = 0
  for i in range(n):
    sm += lcm // a[i]
  print(sm)

Submission status: Runtime Error

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

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

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

L=1
for i in range(n):
  L = lcm(l, a[i])
ans = 0
L %= mod
for i in range(n):
  ans += l * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)

Submission status: Runtime Error

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

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

n = int(input())

l =1
a = list(map(int, input().split()))
for k in a:
    l = lcm(l,k)
b =[]
for k in a:
    b.append(l/k)
mod = 1000000007
s =0
for k in b:
    s+=k%mod
    s%=mod
print(int(s))

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    if (y == 0):
        return x
    else:
        return gcd(y, x % y)
ans = 0
n = input()
while (1):
    ans = 0
    if (n):
        pass
    else:
        break
    s = 1
    a = []
    a = input().split()
    for i in a:
        i = int(i)
        s = s // gcd(max(s, i), min(s, i)) * i
    for i in a:
        i = int(i)
        ans = (ans + s // i) % 1000000007
    print(ans)
    n = input()

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    if (y == 0):
        return x
    else:
        return gcd(y, x % y)
ans = 0
n = input()
while (1):
    if (n):
        pass
    else:
        break
    s = 1
    a = []
    a = input().split()
    for i in a:
        i = int(i)
        s = s // gcd(max(s, i), min(s, i)) * i
    for i in a:
        i = int(i)
        ans = (ans + s // i) % 1000000007
    print(ans)

Submission status: Runtime Error

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


def lcm(x,y):
    pre_x=x
    pre_y=y
    if x<y:
        x,y=y,x
    while x%y !=0:
        x,y=y,x%y
    
    return pre_x*pre_y//y

thr=1

l=lcm(A[0],A[1])

for i in range(2,N):
    l=lcm(l,A[i])
    
ans=0
for i in range(N):
    ans+=l//A[i]

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

Submission status: Runtime Error

Solution code:
from math import gcd
# from fractions import gcd
from functools import reduce

def lcm_list(numbers):
    return reduce(lambda x, y: (x * y) // gcd(x, y), numbers, 1)

def main():
    n = int(input())
    # a = [int(x) for x in input().split()]
    a = tuple(map(int, input().split()))
    lcm = lcm_list(a)
    aa = []
    for i in range(len(a)):
        aa.append(lcm // a[i])
    ans = sum(aa) % 1000000007
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
# from fractions import gcd
from functools import reduce

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

def lcm_list(numbers):
    return reduce(lambda x, y: (x * y) // gcd(x, y), numbers, 1)

lcm = lcm_list(a)
aa = []
for i in range(len(a)):
    aa.append(lcm // a[i])
ans = sum(aa) % 1000000007
print(ans)

Submission status: Runtime Error

Solution code:
from fraction import gcd
from functools import reduce

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

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

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

lcm = lcm_list(a)
aa = []
for i in range(len(a)):
    aa.append(lcm // a[i])
ans = sum(aa) % 1000000007
print(ans)

Submission status: Runtime Error

Solution code:
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
        
def PrimeFactorization(m, primeList):
    pf = {}
    for i in primeList:
        if m < i:
            break
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf


def lcmlist(l, primeList):
    from collections import defaultdict
    d = defaultdict(int)
    for i in set(l):
        for k, v in PrimeFactorization(i, primeList).items():
            if v > d[k]:
                d[k] = v
    n = 1
    for k, v in d.items():
        n *= k ** v
    return n

n=int(input())
a=list(map(int,input().split()))
l=get_sieve_of_eratosthenes(max(a))
x=lcmlist(a,l)
ans=0
for i in a:
  ans+=x//i
  ans%=1000000007
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
lcm = L[0]*L[1]//gcd(L[0],L[1])
for i in range(2,n):
  p = gcd(L[i],lcm)
  lcm = L[i]*lcm//p
ans = 0
for i in range(n):
  ans = (ans+((lcm//L[i])%m))%m
print(ans)