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

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

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

lcm = A[0]
for a in A[1:]:
    lcm = lcm_(lcm, a)

MOD = int(1e9) + 7
sum_ = 0
for a in A:
    sum_ += lcm // a
    sum_ %= MOD

print(sum_)

Submission status: Runtime Error

Solution code:
import math

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

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

lcm = A[0]
for a in A[1:]:
    lcm = lcm_(lcm, a)

MOD = int(1e9) + 7
sum_ = 0
for a in A:
    sum_ += lcm // a
    sum_ %= MOD

print(sum_)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7

pf = np.zeros((n, a.max()//2), dtype=np.int)
for i in range(n):
  while a[i] % 2 == 0:
    a[i] //= 2
    pf[0] += 1
  d = 3
  while d <= np.int(np.sqrt(a[i])):
    while a[i] % d == 0:
      a[i] //= d
      pf[d//2] += 1
    d += 2
  if a[i] > 1:
    pf[a[i]//2] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b_sum += 2 ** b_pf[0] + np.arange(3, 2*pf.shape[1]+2, 2) ** b_pf[1:]
  b_sum %= mod
print(b_sum)

Submission status: Runtime Error

Solution code:
def factorization(n):
    lst, 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
            lst.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if lst == []:
        lst.append([n, 1])
    return lst

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

soinsu = {}
factrized_a = []
for i in range(n):
    lst = factorization(a[i])
    factrized_a.append(lst)
    for sosu, josu in lst:
        try:
            before_josu = soinsu[sosu]
        except KeyError:
            before_josu = 0
        soinsu[sosu] = max(before_josu, josu)

ans = 0
for i in range(n):
    lst = factrized_a[i]
    copied_soinsu = soinsu.copy()
    for sosu, josu in lst:
        copied_soinsu[sosu] -= josu
    bi = 1
    for sosu, josu in copied_soinsu.items():
        bi = bi * (sosu**josu) % mod
    ans = (ans + bi) % mod

print(ans)

Submission status: Runtime Error

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

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

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

    return arr

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

soinsu = [0 for _ in range(1001)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu[:]
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1001):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)

Submission status: Runtime Error

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

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

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

    return arr

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

soinsu = [0 for _ in range(1001)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu.copy()
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1001):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)

Submission status: Runtime Error

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

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

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

    return arr

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

soinsu = [0 for _ in range(1000)]
for i in range(n):
    lst = factorization(a[i])
    for ind, jousu in lst:
        soinsu[ind] = max(soinsu[ind], jousu)

ans = 0
for i in range(n):
    lst = factorization(a[i])
    copied_soinsu = soinsu.copy()
    for ind, jousu in lst:
        copied_soinsu[ind] -= jousu
    bi = 1
    for j in range(1000):
        bi = bi * (j**copied_soinsu[j]) % mod
    ans = (ans + bi) % mod

print(ans)

Submission status: Runtime Error

Solution code:
import math

b=int(input())

a = list(map(int, input().split()))
ans = a[0]
for i in range(1, b):
    ans = ans * a[i] // math.gcd(ans, a[i])

c=0

for j in range(b):
  c+=ans/a[j]

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

Submission status: Runtime Error

Solution code:
import math

b=int(input())

a = list(map(int, input().split()))
ans = a[0]
for i in range(1, b):
    ans = ans * a[i] // math.gcd(ans, a[i])

c=0

for j in range(b):
  c+=ans/a[j]

print(int(c))

Submission status: Runtime Error

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

#input
N = int(input())
A = [int(input()) for _ in range(N)]

#output
import fractions, functools
import numpy as np

mod = 10**9 + 7

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

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

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

print(answer % mod)

Submission status: Runtime Error

Solution code:
import math

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

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

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

lcms = [lcm_pair(a[i-1], a[i+1]) for i in range(1, n-1)]
lcmlcm = lcm(lcms)
lcm_max_pos = lcms.index(max(lcms)) + 1
b = lcmlcm

ll = lcmlcm
for i in range(lcm_max_pos+1, n):
    ll = int((ll / a[i])) * a[i-1]
    b += ll

ll = lcmlcm
for i in range(lcm_max_pos, 0, -1):
    ll = int((ll / a[i-1])) * a[i]
    b += ll

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

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n=int(input())
l=list(map(int,input().split()))
a=lcm_list(l)
ans_l = []
for i in l:
    ans_l.append(a/i)
print(int(sum(ans_l)%(10**9+7)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n=int(input())
l=list(map(int,input().split()))
a=lcm_list(l)
ans_l = []
for i in l:
    ans_l.append(a/i)
print(int(sum(ans_l)%(10**9+7)))

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

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

c = A[0]
for a in A[1:]:
  c = lcm(c, a)

ans = 0
for a in A:
  ans += c//a
  ans %= (1e9+7)
  
print(int(ans))

Submission status: Runtime Error

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

def GCD(a, b):
    if a > b:
        a,b = b,a
    remain = b % a
    if remain == 0:
        return a
    else:
        return GCD(a, remain)

def LCM(a, b):
    return a * b // GCD(a, b)

if N == 1:
    print(1)

lcm = LCM(A_List[0], A_List[1])
if N > 2:
    for i in range(2, len(A_List)):
        lcm = LCM(lcm, A_List[i])

B_list = []
for i in range(len(A_List)):
    B_list.append(lcm // A_List[i])

print(sum(B_list) % (10 ** 9 + 7))

Submission status: Runtime Error

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

def GCD(a, b):
    if a > b:
        a,b = b,a
    remain = b % a
    if remain == 0:
        return a
    else:
        return GCD(a, remain)

def LCM(a, b):
    return a * b // GCD(a, b)

if N == 1:
    print(1)

lcm = LCM(A_List[0], A_List[1])
for i in range(2, len(A_List)):
    lcm = LCM(lcm, A_List[i])

B_list = []
for i in range(len(A_List)):
    B_list.append(lcm // A_List[i])

print(sum(B_list) % (10 ** 9 + 7))

Submission status: Runtime Error

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

def GCD(a, b):
    if a > b:
        a,b = b,a
    remain = b % a
    if remain == 0:
        return a
    else:
        return GCD(a, remain)

def LCM(a, b):
    return a * b // GCD(a, b)

lcm = LCM(A_List[0], A_List[1])
for i in range(2, len(A_List)):
    lcm = LCM(lcm, A_List[i])

B_list = []
for i in range(len(A_List)):
    B_list.append(lcm // A_List[i])

print(sum(B_list) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

mod=10**9+7

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
  
for i in range(N):
  i_sum += koubai//A[i]

print(i_sum % mod)

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

mod=10**9+7

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
  
for i in range(N):
  i_sum += koubai//A[i]

i_sum %= mod

print(i_sum)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import fractions

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

N = int(input())
A = []

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
  
for i in range(N):
  i_sum += koubai/A[i]

int(i_sum)
i_sum %= 1000000007

print(int(i_sum))

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
  
for i in range(N):
  i_sum += koubai/A[i]

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
  
for i in range(N):
  i_sum += koubai/A[i]

int(i_sum)
i_sum %= 1000000007

print(int(i_sum))

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
 
for i in range(N):
  i_sum += koubai/A[i]

int(i_sum)
i_sum %= 1000000007

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
 
for i in range(N):
  i_sum += koubai/A[i]

int(i_sum)
i_sum %= 1000000007

print(int(i_sum))

Submission status: Runtime Error

Solution code:
import fractions

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

N = int(input())
A = []

i_sum = 0

tmp = input().split()
for i in range(N):
  A.append(int(tmp[i])) 
  
koubai = lcm(A[0], A[1])
for i in range(2,N):
  koubai = lcm(koubai,A[i])
 
for i in range(N):
  i_sum += koubai/A[i]

int(i_sum)
i_sum %= 1000000007

print(int(i_sum))

Submission status: Runtime Error

Solution code:
P=1000000007
def power(x,p):
  if(p==0):
    return 1;
  if(p%2):
    return power(x,p-1)*x%P;
  a=power(x,p//2);
  return a*a%P;
def inv(x):
  return power(x,P-2);
N=int(input());A=list(map(int,input().split()));
#N=10000;A=[1000000 for i in range(N)];
L=[0 for i in range(max(A)+1)]
for a in A:
  t=a;i=2;
  while(i**2<=a):
    c=0;
    while(t%i==0):
      t/=i;c+=1;
    L[i]=max(L[i],c)
    i+=1;
  if(t!=1):
    L[t]=max(L[t],1)
    
l=1;
for i in range(2,len(L)):
  l=l*power(i,L[i])%P;
b=0;
for a in A:
  b=(b+inv(a))%P
print(l*b%P)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(a) for a in 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.append([i, cnt])
 
    if temp != 1:
        arr.append([temp, 1])
 
    if arr == []:
        arr.append([n, 1])
 
    return arr
 
 
mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]
 
Z = 1
for n in divs_set:
    Z = Z * (n ** divs_powers[n])
 
B = [0] * N
for i, a in enumerate(A):
    B[i] = int(Z / a) % (10 ** 9 + 7)
 
print(int(sum(B)) % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(a) for a in 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.append([i, cnt])

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

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

    return arr


mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]

Z = 1
for n in divs_set:
    Z = Z * (n ** divs_powers[n])

B = [0] * N
for i, a in enumerate(A):
    B[i] = int(Z / a) % (10 ** 9 + 7)

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

Submission status: Runtime Error

Solution code:
N=input()
A = [int(a) for a in 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.append([i, cnt])

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

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

    return arr

mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]

Z = 1
for n in divs_set:
    Z = Z*(n**divs_powers[n])

B = [0]*N
for i, a in enumerate(A):
    B[i] = int(Z/a)%(10**9+7)

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(a) for a in 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.append([i, cnt])

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

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

    return arr

mat = [1]
divs_set = set()
divs_powers = {}
for a in A:
    tmp = factorization(a)
    for div in tmp:
        if div[0] not in divs_set:
            divs_set.add(div[0])
            divs_powers[div[0]] = div[1]
        else:
            if divs_powers[div[0]] < div[1]:
                divs_powers[div[0]] = div[1]

Z = 1
for n in divs_set:
    Z = Z*(n**divs_powers[n])

B = [0]*N
for i, a in enumerate(A):
    B[i] = int(Z/a)

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
n=int(input())
a=[int(x) for x in input().split()]
mod=10**9+7
b=[]
lcm=1
from math import gcd
for ai in a:
    lcm=ai*lcm//gcd(ai,lcm)
ans=0
for ai in a:
    ans+=lcm//ai
    ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = sorted(list(pn_list.keys()))[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in sorted(list(pn_list.keys())):
            if npn % i == 0:
                break
            if (i ** 2) > npn:
                pn_flg = 1
                break
        if pn_flg == 1:
            break # 素数が見つかったらbreak
        else:
            npn += 2
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 5
#s ="12 12 12 12 12"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
#sqr_max_a = int(1.0 * 10**6)
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
pn_lcm = []
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
            pn_lcm.append(i)
    if check_a(n,a) == "ok":
        break

for i in a:
    if i > 1:
        pn_lcm.append(i)

min_bsum = int(0)
for i in aa:
    b = 1
    aaa = i
    for j in pn_lcm:
        if aaa % j == 0:
            aaa = aaa / j
        else:
            b = b * j
    min_bsum = min_bsum + b

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = sorted(list(pn_list.keys()))[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in sorted(list(pn_list.keys())):
            if npn % i == 0:
                break
            if (i ** 2) > npn:
                pn_flg = 1
                break
        if pn_flg == 1:
            break # 素数が見つかったらbreak
        else:
            npn += 2
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 3
#s ="1000000 999999 999998"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
#sqr_max_a = int(1.0 * 10**6)
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = int(1)
for i in pn_list.keys():
    lcm = lcm * (i ** pn_list[i])
for i in a:
    lcm = lcm * i

min_bsum = int(0)
for i in aa:
    min_bsum += lcm / i

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

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())
a=[int(i) for i in input().split()]
tmp=1
for i in a:
	tmp=lcm(i,tmp)
mod=1e9+7
print(int(sum(tmp//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())
a=[int(i) for i in input().split()]
tmp=1
for i in a:
	tmp=lcm(i,tmp)
mod=1e9+7
ans=int(0)
for i in a:
	ans=(ans+tmp//i)%mod
print(int(ans))

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())
a=[int(i) for i in input().split()]
tmp=1
for i in a:
	tmp=lcm(i,tmp)
mod=1e9+7
ans=int(0)
for i in a:
	ans=(ans+tmp/i)%mod
print(int(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = list(pn_list.keys())[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list.keys():
            if npn % i > 0:
                pn_flg += 1
        if pn_flg == len(pn_list.keys()):
            break # 素数が見つかったらbreak
        else:
            npn += 2
            pn_flg = 0
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 3
#s ="1000000 999999 999998"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = 1
for i in pn_list.keys():
    lcm = lcm * (i ** pn_list[i])
for i in a:
    lcm = lcm * i

min_bsum = 0
for i in aa:
    min_bsum += lcm / i

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = list(pn_list.keys())[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list.keys():
            if npn % i > 0:
                pn_flg += 1
        if pn_flg == len(pn_list.keys()):
            break # 素数が見つかったらbreak
        else:
            npn += 2
            pn_flg = 0
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 3
#s ="1000000 999999 999998"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = 1.0
for i in pn_list.keys():
    lcm = lcm * (i ** pn_list[i])

min_bsum = 0.0
for i in aa:
    min_bsum += lcm / i

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = list(pn_list.keys())[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list.keys():
            if npn % i > 0:
                pn_flg += 1
        if pn_flg == len(pn_list.keys()):
            break # 素数が見つかったらbreak
        else:
            npn += 2
            pn_flg = 0
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = 1
for i in pn_list.keys():
    lcm = lcm * i ** pn_list[i]

min_bsum = 0
for i in aa:
    min_bsum += lcm / i

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

Submission status: Runtime Error

Solution code:
import fractions
import functools
import sys

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

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)
"""
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
"""
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

lcm_A = functools.reduce(lcm_base, A, 1)
B = [None]*N
for i in xrange(N):
    B[i] = lcm_A//A[i]

print(sum(B)%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions 
#from functools import reduce
import functools

MOD = 10**9+7


def main():
    N, *A = map(int, open(0).read.split())
    # N = int(input())
    # A = list(map(int, input().split()))

    # def lcm(x, y):
    #     return x * y // fractions.gcd(x, y)
        
    
    # x = functools.reduce(lcm, A, 1)

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

    
    b = sum(x//a%MOD for a in A)
    print(b%MOD)
if __name__== "__main__":
    main()

Submission status: Runtime Error

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

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

lcm_A = lcm_list(A)
B = [None]*N
for i in range(N):
    B[i] = lcm_A/A[i]
print(1)
"""
print(int(sum(B)%(10**9+7)))
"""

Submission status: Runtime Error

Solution code:
def gcm(a,b):
  while b: a,b=b,a%b
  return a
def lcm(x,y):
  return x*y//gcm(x,y)

n=int(input())
a=[int(i) for i in input().split()]
l=lcm(a[0],a[1])
for i in range(2,n):
  l=lcm(l,a[i])
ans=0
for num in a:
  ans += l//num
  ans%=10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions 
#from functools import reduce
import functools

MOD = 10**9+7


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

    x = 1
    ans = 0
    # for a in A:
    #     tmp = gcd(x, a)
    #     # ans += (i) * A[i] // tmp + A[i] * x //tmp  
    #     x = (x * a) // tmp

    def lcm(x, y):
        return x * y // fractions.gcd(x, y)
        
    
    x = functools.reduce(lcm, A, 1)
        
    b = sum(x//a for a in A)
    print(b%MOD)
main()

Submission status: Runtime Error

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

MOD = 10**9+7


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

    x = 1
    ans = 0
    # for a in A:
    #     tmp = gcd(x, a)
    #     # ans += (i) * A[i] // tmp + A[i] * x //tmp  
    #     x = (x * a) // tmp
    x = functools.reduce(functools.gcd, A, 1)
        
    b = 0
    A = np.array(A)
    # for a in A:
    #     b += x // a
    b = np.sum(x//A, axis=0)
    print(b%MOD)
main()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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)

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

lcm_A = float(lcm_list(A))

B = [None]*N
for i in range(N):
    B[i] = lcm_A/A[i]

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

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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)

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

lcm_A = lcm_list(A)

B = [None]*N
for i in range(N):
    B[i] = lcm_A/A[i]

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

Submission status: Runtime Error

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

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

lcm_A = lcm_list(A)

B = [None]*N
for i in range(N):
    B[i] = lcm_A/A[i]

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

Submission status: Runtime Error

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

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

lcm_A = lcm_list(A)

B = [None]*N
for i in range(N):
    B[i] = lcm_A/A[i]

print(sum(B)%(10**9+7))

Submission status: Runtime Error

Solution code:
import functools
import sys
from fractions import gcd

sys.setrecursionlimit(100000)

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

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

def divide(number_a, number_b):
    return number_a / number_b

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

lcm = lcm_list(As)

divide_parted = functools.partial(divide, lcm)

divided_list = list(map(divide_parted, As))
result = 0

for d in divided_list:
  result += d
  if result >= 1000000007:
    result = result % 1000000007
    
print(int(result))

Submission status: Runtime Error

Solution code:
import functools
from fractions import gcd

sys.setrecursionlimit(100000)

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

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

def divide(number_a, number_b):
    return number_a / number_b

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

lcm = lcm_list(As)

divide_parted = functools.partial(divide, lcm)

divided_list = list(map(divide_parted, As))
result = 0

for d in divided_list:
  result += d
  if result >= 1000000007:
    result = result % 1000000007
    
print(int(result))