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 sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
# 最小公倍数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


## 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

def many_lcm(l):
    for i in range(len(l)-1):
        if i == 0:
            ans = lcm(l[0], l[1])
        else:
            ans = lcm(l[i+1], ans)
    return ans
N = INT()
A = LIST()

lm = many_lcm(A)
# print(l)
B = []
for a in A:
    B.append(lm // a)
print(sum(B) % mod)

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
## 最小公倍数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


## 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

def many_lcm(l):
    for i in range(len(l)-1):
        if i == 0:
            ans = lcm(l[0], l[1])
        else:
            ans = lcm(l[i+1], ans)
    return ans
N = INT()
A = LIST()

lm = many_lcm(A)
# print(l)
B = []
for a in A:
  B.append(lm // a)
print(sum(B) % mod)

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
## 最小公倍数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


## 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

def many_lcm(l):
    for i in range(len(l)-1):
        if i == 0:
            ans = lcm(l[0], l[1])
        else:
            ans = lcm(l[i+1], ans)
    return ans
N = INT()
A = LIST()

l = many_lcm(A)
# print(l)
B = []
for a in A:
  B.append(l // a)
print(sum(B) % mod)

Submission status: Runtime Error

Solution code:
def extgcd(a,b):
  r=[1,0,a]
  w=[0,1,b]
  while w[2]!=1:
    q=r[2]//w[2]
    r2=w
    w2=[r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r=r2
    w=w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x=extgcd(a,m)[0]
  return (m+x%m)%m

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]

prime=primes(int(10**3)+1)

def fact2(n):
  l=primes(int(n**0.5)+1)
  L=[]
  for i in range(len(l)):
    ct=0
    while n%l[i]==0:
      n=n//l[i]
      ct+=1
    if ct!=0:
      L.append((l[i],ct))
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**6)]
mod=10**9+7
for i in range(n):
  x=fact2(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

from functools import reduce
from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
## 最小公倍数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


## 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

def many_lcm(l):
    for i in range(len(l)-1):
        if i == 0:
            ans = lcm(l[0], l[1])
        else:
            ans = lcm(l[i+1], ans)
    return ans
N = INT()
A = LIST()

l = many_lcm(A)
# print(l)
B = []
for a in A:
  B.append(l // a)
print(sum(B) % mod)

Submission status: Runtime Error

Solution code:
import math

def lcm(x, y):
    return x // math.gcd(x, y) * y
n = int(input())
a = list(map(int, input().split(' ')))
l = 1
for ai in a:
    l = lcm(l, ai)
mod = 1000000007
ans = 0
for ai in a:
    ans += l // ai
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
def extgcd(a,b):
  r=[1,0,a]
  w=[0,1,b]
  while w[2]!=1:
    q=r[2]//w[2]
    r2=w
    w2=[r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r=r2
    w=w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x=extgcd(a,m)[0]
  return (m+x%m)%m

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]

prime=primes(int(10**3)+1)

def fact2(n):
  l=prime
  L=[]
  for i in range(len(l)):
    ct=0
    while n%l[i]==0:
      n=n//l[i]
      ct+=1
    L.append((l[i],ct))
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

print(fact2(12))
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**6)]
mod=10**9+7
for i in range(n):
  x=fact2(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
 
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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]
 
cand = lcm_list(As)
 
sum = 0
 
for num in As:
    sum = sum + cand // num
 
print(sum % (10**9 + 7))
from functools import reduce
import math
 
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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]
 
cand = lcm_list(As)
 
sum = 0
 
for num in As:
    sum = sum + cand // num
 
print(sum % int(1e9+7) )

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

from functools import reduce
from math import gcd as gcd_base  # from fractions import gcd
gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数

N = INT()
A = LIST()

l = lcm(*A)
B = []
for a in A:
  B.append(l // a)
print(sum(B) % mod)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
 
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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]
 
cand = lcm_list(As)
 
sum = 0
 
for num in As:
    sum = sum + cand // num
 
print(sum % (10**9 + 7))

Submission status: Runtime Error

Solution code:
def extgcd(a,b):
  r=[1,0,a]
  w=[0,1,b]
  while w[2]!=1:
    q=r[2]//w[2]
    r2=w
    w2=[r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r=r2
    w=w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x=extgcd(a,m)[0]
  return (m+x%m)%m

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]
def fact2(n):
  l=primes(int(n**0.5)+1)
  L=[]
  for i in range(len(l)):
    ct=0
    while n%l[i]==0:
      n=n//l[i]
      ct+=1
    L.append((l[i],ct))
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**6)]
mod=10**9+7
for i in range(n):
  x=fact2(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = lcm_list(As)

ans = sum([l // x for x in a]) % int(1e9+7)
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = lcm_list(As)

ans = sum([l // x for x in a]) % int(1e9+7)
print(sum)

Submission status: Runtime Error

Solution code:
import math
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
  
def prime_factor(n):
    ans = defaultdict(int)
    while n % 2 == 0: 
        ans[2] += 1
        n = n / 2
          
    for i in range(3,int(math.sqrt(n))+1,2): 
        while n % i== 0: 
            ans[i] += 1
            n = n / i 
    if n > 2: 
        ans[n] += 1
    return ans

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

facts = defaultdict(int)
for a in ai:
    tmp = prime_factor(a)
    for i in tmp.keys():
        facts[i] = max(facts[i], tmp[i])

m = 1
for i in facts.keys():
    m *= i ** facts[i]

ans = 0
for a in ai:
    ans += m // a
    ans %= (10**9 + 7)
print(int(ans))

Submission status: Runtime Error

Solution code:
#coding:utf-8

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

mod = 10 ** 9 + 7

#最小公倍数を取得
g = a[0]
for num in a[1:]:
    g = g * num // gcd(num, g)

ans = 0
#計算後なのでmodオッケー
l = g % mod
for num in a:
    ans += l * pow(num, nod-2, mod)
    ans %= mod
print(ans % mod)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

N = int(input().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = As[0]
for i in range(1, N):
    cand = cand * As[i] // fractions.gcd(cand, As[i])

sum = 0

for num in As:
    sum = sum + cand / num

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

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = lcm_list(As)

sum = 0

for num in As:
    sum = sum + cand / num

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

Submission status: Runtime Error

Solution code:
import fractions as math
from functools import reduce


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

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)

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

Submission status: Runtime Error

Solution code:
import fractions

mod = 1e9 + 7;

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

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

sum = 0
for i in A:
  sum += l // i

print(sum % mod)

Submission status: Runtime Error

Solution code:
import fractions

mod = 1e9 + 7;

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

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

sum = 0
for i in A:
  sum += l // i

print(int(sum % mod))

Submission status: Runtime Error

Solution code:
import math
from collections import defaultdict
  
def prime_factor(n):
    ans = defaultdict(int)
    while n % 2 == 0: 
        ans[2] += 1
        n = n / 2
          
    for i in range(3,int(math.sqrt(n))+1,2): 
        while n % i== 0: 
            ans[i] += 1
            n = n / i 
    if n > 2: 
        ans[n] += 1
    return ans

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

facts = defaultdict(int)
for a in ai:
    tmp = prime_factor(a)
    for i in tmp.keys():
        facts[i] = max(facts[i], tmp[i])

m = 1
for i in facts.keys():
    m *= i ** facts[i]

ans = 0
for a in ai:
    ans += m // a
    ans %= (10**9 + 7)
print(int(ans))

Submission status: Runtime Error

Solution code:
import fractions

inv = [1]*(10**6+10)
for i in range(2,len(inv)):
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD

def lcm(a,b):
    return a*b*inv[fractions.gcd(a,b)]

MOD = (10**9)+7
n = int(input())
a = list(map(int,input().split()))
l = 1
for i in range(n):
    l = lcm(l,a[i])  #mod
l %= MOD

ans = 0
for i in range(n):
    ans = (ans+(l*inv[a[i]])%MOD)%MOD
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

mod = 10**9 + 7

from fractions import gcd
from functools import reduce

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

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

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

x = lcm_list(a)
# print(x)

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

print(int(ans)%mod)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce


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


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


n = int(sys.stdin.readline())
l = [int(_) for _ in sys.stdin.readline().split()]
x = lcm_list(l)
ans = 0
for i in range(n):
    ans += x // l[i]
    ans %= (10**9 + 7)
print(ans)

Submission status: Runtime Error

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

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


lcm=[0]*(10**3+5)



for i in range(N):
    a=A[i]
    b=int(math.sqrt(a))+1
    for j in range(2,b):
        temp=0
        while a%j==0:
            a=a//j
            temp+=1
        lcm[j]=max(lcm[j],temp)
    if a!=1:
        lcm[a]+=1
                
        
l=1
for j in range(2,len(lcm)):
    l*=pow(j,lcm[j])
    

ans=0
mod=10**9+7

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

mod = 10**9 + 7

from fractions import gcd
from functools import reduce

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

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

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

x = lcm_list(a)

# print(x)

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

print(int(ans)%mod)

Submission status: Runtime Error

Solution code:
from typing import Dict

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


def pow(a, b, mod=10 ** 9 + 7):
    if b == 0:
        return 1
    elif b == 1:
        return a
    elif b % 2 == 0:
        return (pow(a, b // 2) ** 2) % mod
    else:
        return (a * pow(a, b // 2) ** 2) % mod


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


def factorize(x):
    ans = {}
    v = 2
    while v * v <= x:
        if x % v == 0:
            ans[v] = 0
            while x % v == 0:
                x //= v
                ans[v] += 1
        v += 1
    if x != 1:
        ans[x] = 1
    return ans


def merge(d: Dict[int, int], c: Dict[int, int]):
    for k, v in c.items():
        if k not in d:
            d[k] = v
        d[k] = max(d[k], v)


tmp = {}
for v in A:
    merge(tmp, factorize(v))
t = 1
mod = 10 ** 9 + 7
for k, v in tmp.items():
    t *= k ** v
    t %= mod
ans = 0
for a in A:
    ans += t * inv(a)
print(ans % mod)

Submission status: Runtime Error

Solution code:
import sys
 
input = sys.stdin.readline
 
ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
 
import sys
import numpy as np
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):
    ans = 1
    for num in numbers:
        ans = ans * num // fractions.gcd(ans,num)
    return ans
 
def LI():
  return [int(s) for s in input().split()]
 
 
input = sys.stdin.readline
ri = lambda: int(input())
ril = lambda: list(map(int, input().split()))
 
N = ri()
A_s = ril()
mod = 10**9 + 7
 
#l = lcm_list(A_s)
l = 1
for num in numbers:
    l = l * num // fractions.gcd(l,num)
 
print(sum(map(lambda x : l//x, A_s)) % mod)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

read = sys.stdin.read


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def sieve_of_eratosthenes(n):
    sieve = [True] * n
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]


def prime_factorize(n):
    a = []
    if n == 1:
        return [1]
    for i in primes:
        if n == 1:
            break
        while n % i == 0:
            a.append(i)
            n //= i
    return a


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

primes = sieve_of_eratosthenes(10 ** 6)
dic = {i: 0 for i in primes}

n = len(primes)
p = [0] * n
for i in A:
    tmp = Counter(prime_factorize(i))
    for key, value in tmp.items():
        # print(key, value)
        if dic[key] < value:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    if j == 0:
        continue
    lcm *= pow(i, j, mod)
    lcm %= mod

answer = 0
for i in A:
    answer += lcm * pow(i, mod - 2, mod)
    answer %= mod

print(answer)

Submission status: Runtime Error

Solution code:
import sys
 
input = sys.stdin.readline
 
ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

import sys
import numpy as np
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):
    ans = 1
    for num in numbers:
        ans = ans * num // fractions.gcd(ans,num)
    return ans
 
def LI():
  return [int(s) for s in input().split()]
 
 
input = sys.stdin.readline
ri = lambda: int(input())
ril = lambda: list(map(int, input().split()))
 
N = ri()
A_s = ril()
mod = 10**9 + 7
 
#l = lcm_list(A_s)
l = 1
for num in numbers:
    ans = ans * num // fractions.gcd(ans,num)
return ans
 
print(sum(map(lambda x : l//x, A_s)) % mod)

Submission status: Runtime Error

Solution code:
n = int(input())
an = list(map(int, input().split()))
import sys
sys.setrecursionlimit(100000000) 

from fractions import gcd
from functools import reduce

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

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

lcma = lcm_list(an)
bn = []
for a in an:
    bn.append(lcma / a)

sumbn = int(sum(bn) % 1000000007)

print(sumbn)

Submission status: Runtime Error

Solution code:
n = int(input())
an = list(map(int, input().split()))
import sys
sys.setrecursionlimit(100000000000) 

from fractions import gcd
from functools import reduce

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

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

lcma = lcm_list(an)
bn = []
for a in an:
    bn.append(lcma / a)

sumbn = int(sum(bn) % 1000000007)

print(sumbn)

Submission status: Runtime Error

Solution code:
n = int(input())
an = list(map(int, input().split()))
import sys
sys.setrecursionlimit(100000) 

from fractions import gcd
from functools import reduce

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

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

lcma = lcm_list(an)
bn = []
for a in an:
    bn.append(lcma / a)

sumbn = int(sum(bn) % 1000000007)

print(sumbn)

Submission status: Runtime Error

Solution code:
import testcase
n = 10**4
lst1 = list(map(int,testcase.integers(10**4,1,10**5+1).split()))
mod = 10**9+7

import math
#リスト l の最大公約数
def lcmlist(l):
    a = l[0]
    for i in range(len(l)):
        a = int(a)
        a = a*l[i]//math.gcd(a,l[i])
    return int(a)

g = lcmlist(lst1)
ans = 0
for i in range(n):
    ans += g//lst1[i]
print(ans%mod)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
  while(b > 0):
    a %= b
    swap(a, b)
  return a
def lcm(a, b):
  return a * b // gcd(a,b)
n = int(input())
md = int(1e9 + 7)
a = [int(e) for e in input().split()]
x = 1
for j in range(n):
  x = lcm(x, a[j])
ans = 0
for i in range(n):
  ans += lcm // a[i]
ans %= md
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import fractions
N=int(input())
A=list(map(int,input().split()))
#def lcm(x,y):
 #   l=x*y/fractions.gcd(x,y)
  #  return l
l=A[0]
for i in range(N-1):
    l=int((A[i+1]*l)/fractions.gcd(A[i+1],l))
ans=0
for i in range(N):
    ans+=l//A[i]
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import fractions
N=int(input())
A=list(map(int,input().split()))
def lcm(x,y):
    l=x*y/fractions.gcd(x,y)
    return l
l=A[0]
for i in range(N-1):
    l=int(A[i+1]*l/fractions.gcd(A[i+1],l))
ans=0
for i in range(N):
    ans+=l//A[i]
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
from fraction import gcd
n=int(input())
a=list(map(int,input().split()))
t=1
for i in a:
  t=t/gcd(t,i)*i
ans=0
MOD=1000000007
for i in a:
  ans+=t/i
  ans%=MOD
print(ans)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline
import fractions



def main():
    N=int(input())
    A = [int(x) for x in input().split()]
    MOD=10**9+7
    
    x = 1
    for a in A:
        x = (a *x )// fractions.gcd(a, x)

    ans=0
    for a in A:
      ans+=x//a

    print(ans%mod)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


from fractions import gcd
from functools import reduce

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

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

lcma = lcm_list(an)
bn = []
for a in an:
    bn.append(lcma / a)

sumbn = int(int(sum(bn)) % 1000000007)

print(sumbn)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = lcm_list(As)

sum = 0

for num in As:
    sum = sum + cand / num

print(sum)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def lcm_mod(a, mod=-1):
    x = a[0]
    if mod == -1:
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
    else:
        for i in range(1, len(a)):
            x *= (a[i] * mod_inv(gcd(x, a[i]), P)) % P
    return x

_,a = [list(map(int, s.split())) for s in open(0)]

P = 10**9 + 7
N = max(a)

lcm_ = lcm_mod(a, P)

ans = 0
for x in a:
    ans += int((lcm_*inv_t[x])%P)
print(int(ans%P))

Submission status: Runtime Error

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


from fractions import gcd
from functools import reduce

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

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

lcma = lcm_list(an)
bn = []
for a in an:
    bn.append(lcma / a)

sumbn = int(sum(bn) % 1000000007)

print(sumbn)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

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().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = lcm_list(As)

sum = 0

for num in As:
    sum = sum + cand / num

print(sum)

Submission status: Runtime Error

Solution code:
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
  
N = int(input())
lst = list(map(int, input().split()))
const = 10**9 + 7

L = lcm(lst)
answer = 0
for i in lst:
  answer += L / i
answer %= const

print(int(answer))

Submission status: Runtime Error

Solution code:
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
  
N = int(input())
lst = list(map(int, input().split()))
const = 10**9 + 7

L = lcm(lst)
answer = 0
for i in lst:
  answer += L / i
answer %= const

print(answer)

Submission status: Runtime Error

Solution code:
import fractions
 
n = int(input())
a = list(map(int, input().split()))
 
num = a[0]
for i in range(1, n):
	num = (num * a[i]) // fractions.gcd(num, a[i])
 
ans = 0
for i in range(n):
	ans += (num//a[i]) % 1000000007
 	if ans > 1000000007:
      	ans = ans % 1000000007
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)

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    l = int(1)
    for e in a:
        l = lcm(l,e)
    s = int(0)
    for e in a:
        s += l//e
    mod = int(1000000007)
    print(int(s % mod))