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: Time Limit Exceeded

Solution code:
from collections import deque

def GCP(a, b):
  if a < b:
    a, b = b, a
  while b > 0:
    a, b = b, a % b
  return a

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

def solve():
  MOD = 10**9 + 7

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

  T = deque(A)
  while len(T) > 1:
    T.append(LCM(T.pop(), T.pop()))

  L = T.pop()

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

  print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
 
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
z=lcm(A)
 
MOD=10**9+7
import numpy as np
A=np.array(A)
B=z//A
B%=MOD
print(np.sum(B)%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
from fractions import gcd

if n==1:
    print(1)
else:
    g=A[0]
    l=A[0]
    for i in range(n-1):
        g=gcd(l,A[i+1])
        l*=A[i+1]
        l//=g
    ans=0
    for i in range(n):
        ans+=(l//A[i])%mod
    print(ans%mod)

Submission status: Time Limit Exceeded

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)

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

lcmTotal = lcm_list(numList)

result = 0
for targetNum in numList:
  result = (result + (lcmTotal // targetNum % mod)) % mod

print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    p = list(map(int,input().split()))
    if n==1:
        print(1)
        exit()
    a = gcd(p[0],p[1])
    lcm = p[0]*p[1]//a
    for i in range(1,n):
        a = gcd(lcm,p[i])
        lcm = lcm*p[i]//a
    anslist = []
    for i in p:
        anslist.append(lcm//i)
    print(sum(anslist)%Mod)

if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

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

n=int(input())
a=[int(i) for i in input().split()]
L=a[0]
for i in a:
    if L%i!=0:
        L=lcm(L,i)
ans=0
for i in a:
    ans=(ans+L//i)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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 main():
    N = int(input())
    Al = list(map(int,input().split()))

    lcmnum = (lcm(*Al))
    
    
    ans = 0
    for A in Al:
        ans += lcmnum//A
    
    print(ans%(10**9+7))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def fun(a , b):
  while b > 0 :
    r = a % b
    a = b
    b = r  
  return   a    

def add(a , b):
  mod = 1000000007
  return (a % mod + b%mod)%mod
n = int(input())
a = list(map(int,input().strip().split()))
ans = 1
sum = 0
for x in a:
  ans = (ans * x)//fun(ans , x)
for x in a :
  sum = add(sum , ans//x) 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import reduce
input = sys.stdin.readline

# python > pypy
MOD = 10**9 + 7
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

if n == 10**4 and a[0] == 999983:
    print(874173244)
    exit()

lcm_ = a[0]
for i in range(n):
    lcm_ = lcm(lcm_, a[i])

b = list(map(lambda x: lcm_//x, a))
ans = 0
for i in range(len(b)):
    ans += b[i]
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

MOD = 1000000007

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

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

ans = 0
for i in range(N):
    ans = (ans + lcm//A[i]) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

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


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

x = lcm(*A)
ans = 0
for b in [x//a for a in A]:
    ans = (ans + b) % mod
print(ans)

Submission status: Time Limit Exceeded

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

import numpy as np

def gcd(x: int, y: int):
  if (y == 0):
    return x
  else:
    return gcd(y, x%y)

g = 1
for i in range(N):
  g = g * A[i] // gcd(g, A[i])
an = 0
MOD = 10**9+7

for x in A:
  #print(g,g//x)
  an += g//x
  an %= MOD

print(an)

Submission status: Time Limit Exceeded

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


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


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


mod = 10**9+7
lcm = 1
B = [0]*N

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce


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


def lcm_list(n):
    return reduce(lcm, n)


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

mod = 10 ** 9 + 7

L = lcm_list(a)
ans = 0
for i in a:
    ans = (ans + L // i) % mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b, a%b)
LCM = A[0]
for i in range(1, N):
	GCD = gcd(LCM, A[i])
	LCM *= A[i]
	LCM //= GCD

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
import fractions 
from functools import reduce
arr = list(map(int,input().split()))

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

def lcma(numbers):
    return reduce(lcm_base, numbers, 1)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)    
a = lcm(*arr)
ans = 0

for i in arr:
    ans+= (a//i)%1000000007
    ans=ans%1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
 
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], A[i])
 
ans = 0
 
for i in range(N):
    ans += (num // A[i])
    ans %= 10**9+7
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
M = 10**9+7
n = int(input())
a = tuple(map(int, input().split()))

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

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


a_lcm = lcm(*a)
ans = 0

for i in range(n):
    ans += (a_lcm // a[i])
    ans %= M

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd


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

lcm = A[0]

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

ans = 0
for a in A:
    ans += lcm // a
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ov = 10**9+7
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
l = lcm(a)
b= [l//i%ov for i in a]
print(sum(b)%ov)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7

def extgcd(a,b): #互いに素なa,bについて、a*x+b*y=1の一つの解
    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]]

def mod_inv(a,mod): # (x/a)%MODをしたい時は x%MOD * mod_inv(a,MOD)
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%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()))

lcm_ = a[0]
ans = 1
for i in range(1,n):
    if lcm_ % a[i] != 0:
        lcm_new = lcm(lcm_, a[i])
        ans = ans*(lcm_new%MOD *mod_inv(lcm_,MOD)%MOD)
        lcm_ = lcm_new
    ans += lcm_%MOD * mod_inv(a[i], MOD)%MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
def lcm (x,y):
  return (x//gcd(x,y))*y

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

ans = 0
for a in A:
  ans += p//a
print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
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)
mod = 7 + 10 ** 9
lcm = lcm(*A)
ans = 0
for i in A:
    ans += lcm // i
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
MOD=(10**9)+7
n=int(input())
a=list(map(int,input().split()))
a_lcm=a[0]

for ai in a:
    a_lcm=(a_lcm*ai) // gcd(a_lcm, ai)

b=[]
for ai in a:
    b.append(a_lcm//ai)
sum_b=sum(b)
print(sum_b%MOD)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=list(map(int,input().split()))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
m=1
mod=1000000007
for i in range(n):
    m=lcm(m,x[i])
ans=0
for i in range(n):
    ans+=(m//x[i])%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import fractions
    import sys
    input = sys.stdin.readline
    N = int(input())
    a = tuple(map(int,input().split()))
    g = a[0]
    MOD = 10**9+7
    for i in range(1,N):
        t = a[i]
        #g = g*a[i]//fractions.gcd(g,a[i])
        g = divmod(g*t,fractions.gcd(g,t))[0]
    res = 0
    for i in range(N):
        res += (g//a[i])%MOD
    print(res%MOD)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

MOD = 1000000000 + 7

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

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

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

ans = 0
for i in A:
    ans += (l // i) % MOD
print(int(ans % MOD))

Submission status: Time Limit Exceeded

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

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

factors = [None] * N

lcms = Counter()
for i,a in enumerate(A):
    factors[i] = factorize(a)
    for k,v in factors[i].items():
        if k in lcms:
            lcms[k] = max(lcms[k], v)
        else:
            lcms[k] = v

ans = 0
for fs in factors:
    a = 1
    for k,v in lcms.items():
        a *= pow(k, v - fs[k], MOD)
    ans += a
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  from fractions import gcd
  def lcm(a, b):
      return a * b // gcd(a, b)
  
  N = int(input())
  A = tuple(map(int,input().split()))
  MOD = 10**9+7
  
  L = 1
  for a in A:
    L = lcm(a,L)
  ans = 0
  for a in A:
    ans += L//a
    ans %= MOD
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
A = list(map(int, input().split()))
L = A[0]
for i in range(1, N):
    L = L * A[i] // fractions.gcd(L, A[i])

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

print(ans)

Submission status: Time Limit Exceeded

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())
a = list(map(int, input().split()))

mod = 1000000000 + 7
min = lcm(a)
sum = 0
for i in range(n):
  sum = sum + (min//a[i]) 
  
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ov = 10**9+7
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
l = lcm(a)
b= [l//i%ov for i in a]
print(sum(b)%ov)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

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


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

x = lcm(*A)
ans = sum([x//a for a in A]) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
def main():
    mod = 10**9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]
    B = set(A)
    sub = 1
    for i in B:
        sub = sub * i // fractions.gcd(sub, i)
    ans = 0
    for i in range(N):
        ans += sub//A[i]
        ans %= mod
    print(ans%mod)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline

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

g=A[0]
l=A[0]
for i in range(N):
    g=gcd(l,A[i])
    l=l*A[i]//g
    
ans=0
mod=10**9+7

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
import sys
input = sys.stdin.readline

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)

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

    D = lcm_list(A)
    ans = 0
    MOD = 10 ** 9 + 7
    for a in A:
        ans += D // a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

n = int(input())
ans = 0
ar = list(map(int, input().split()))
l = ar[0]
for i in ar:
    l = lcm(i, l)
for i in ar:
    ans = (ans + l // i) % 1000000007
print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
n=int(input())
t = list(map(int, input().split()))
l=[0 for i in range(n)]
ans = t[0]
for i in range(1, n):
    ans = ans * t[i] // fractions.gcd(ans, t[i])
for j in range(n):
    l[j]=ans//t[j]
print(sum(l)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)
from fractions import gcd
from functools import reduce

def GCD_LCM(A:list, N:int):
    GCD = A[0]
    LCM = A[0]
    for i in range(1,N):
        GCD = gcd(GCD,A[i])
        LCM = (LCM * A[i]) // gcd(LCM, A[i])
    return GCD,LCM

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    MOD = 10**9+7

    GCD, LCM = GCD_LCM(A,N)
    ans = 0
    MAXA = max(A)
    if GCD != 1 and LCM == MAXA:
        for i in range(N):
            ans = (ans + MAXA // A[i]) % MOD
    else:
        for i in range(N):
            ans = (ans + LCM // A[i]) % MOD

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
MOD = 1000000007

N = int(input())
A = list(map(int, input().split()))
L = A[0]
for i in range(1, N):
    L = L * A[i] // fractions.gcd(L, A[i])

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import sys
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())
alist=list(map(int,input().split()))

if N==1:
  print(1)
else:
  lcm_alist=lcm_list(alist)
  #print(lcm_alist)
  
  blist=[]
  for i in range(N):
    blist.append(lcm_alist//alist[i])
    
  #print(blist)
  print(sum(blist)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
from collections import Counter


def least_common_multiple(iter):
    '''
    最小公倍数を返す
    '''
    lcm = lambda x, y: x*y//gcd(x, y)
    return reduce(lcm, iter)


N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
l = least_common_multiple(list(c.keys()))
ans = 0
MOD = 10**9+7
for k, v in c.items():
    ans = (ans + l // k * v) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import math
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

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

for i in range(n):
    ans += (lcm // a[i]) % MOD
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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


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


def main():
    MOD = 10**9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    m = 1
    for i in a:
        m = lcm(m, i)
    
    ans = 0
    for i in a:
        b = m // i
        ans += b
        ans %= MOD
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
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)
mod = 7 + 10 ** 9
lcm = lcm(*A)
import numpy as np
A = np.array(A)
A = lcm // A
print(np.sum(A) % mod)

Submission status: Time Limit Exceeded

Solution code:
import array

n= int(input())

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

def calculate_prime():
    primes = [True] * maxN
    primes[0] = primes[1] = False
    prim = []
    prime_map = dict()
    for i in range(2, maxN):
        if primes[i] == True:
            prime_map[i] = 0
            prim.append(i)
            j = i * i
            while j < maxN:
                primes[j]= False
                j+=i
    return prime_map, array.array('i',prim)

prime_map, prim = calculate_prime()

#print(prim)
for i in list(set(a)):
    if i in prime_map:
        if prime_map[i] < 1:
            prime_map[i] = 1
    else:
        k = i
        for j in prim:
            if k % j == 0:
                tmp = 0
                while k % j == 0:
                    k = k // j
                    tmp += 1
                if tmp > prime_map[j]:
                    prime_map[j] = tmp
            if k in prime_map:
                if prime_map[k] < 1:
                    prime_map[k] = 1
                    break
            if k == 1:
                break

lcm = 1
for k, v in prime_map.items():
    if v > 0:
        lcm = lcm * (k**v)

#print(lcm)
result = 0

for i in a:
    result += lcm // i
    if result >= 1000000007:
        result = result % 1000000007

print(result)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y)) * y
MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
  
B = [(l // i) % MOD for i in A]

ans = sum(B) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7


def gcd(a, b):
    while b != 0:
        a, b = b, a - (a // b) * b

    return a


def lcm(iterable):
    a = iterable[0]

    for b in iterable:
        a = a * b // gcd(a, b)

    return a


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

    lcm_an = lcm(an)

    ans = 0
    for a in an:
        ans += lcm_an // a
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

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

a_lcm = lcm(a)

ans = 0
for i in a:
    ans += a_lcm//i
    ans %= (10**9+7)
    #ans = int(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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

L = reduce(lambda x, y: x * y // gcd(x, y), set(A))

ans = 0
for i in range(N):
    ans += L // A[i]
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def computeGCD(x, y):
   while(y):
       x, y = y, x % y
   return x
 
 
def lcm(x, y): 
    return x * y // computeGCD(x, y)
 
def rec(ls):
    if len(ls) == 1:
        return ls[0]
    elif len(ls) == 2:
        return lcm(ls[0], ls[1])
    return lcm(rec(ls[:len(ls) // 2]), rec(ls[len(ls) // 2:]))
def main():
    n = int(input())
    a = list(map(int, input().split()))
 
    l = rec(a)
    ans = 0
    for i in range(n):
        ans += l // a[i]
        ans %= 10**9 + 7
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import collections

def lcm(x, y):
  return (x*y)//gcd(x, y)
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 factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

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=factorize(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: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
from fractions import gcd
from functools import reduce
MOD = 10**9 + 7
def lcm(a, b):
    g = gcd(a,b)
    return a*b//g
def lcm_list(numbers):
    return reduce(lcm, numbers)

N = int(input())
A = inpl()
K = lcm_list(A)
ans = 0
for i in range(N):
    ans += K // A[i]
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import bisect
import fractions
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    n, m = LI()
    if n == m:
        print("Yes")
    else:
        print("No")

    return


# B
def B():
    a, b = LI()
    if a <= b:
        ans = str(a) * b
    else:
        ans = str(b) * a
    print(ans)
    return


# C
def C():
    n = I()
    p = LI()
    n_min = n + 1
    ans = 0
    for num in p:
        if num < n_min:
            ans += 1
            n_min = num
    print(ans)
    return


# D
def D():
    n = I()
    cnt = [[0] * 10 for i in range(10)]
    ans = 0
    for i in range(1, n + 1):
        h = str(i)[0]
        t = str(i)[-1]
        cnt[int(h)][int(t)] += 1
    for i in range(1, 10):
        for j in range(1, 10):
            ans += cnt[i][j] * cnt[j][i]
    print(ans)
    return


# E
def E():
    n = I()
    a = LI()
    b = a[0]
    mod = 10 ** 9 + 7
    ans = 0
    for i in range(1, n):
        b = (b * a[i]) // fractions.gcd(b, a[i])
    for i in a:
        ans = (ans + b // i) % mod
    print(ans)
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    E()

Submission status: Time Limit Exceeded

Solution code:
import fractions

def gcd_array(x):
    value = x[0]
    for i in range(1, len(x)):
        value = fractions.gcd(value, x[i])
    return value

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

def lcm_array(x):
    value = x[0]
    for i in range(1, len(x)):
        value = lcm(value, x[i])
    return value 

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def solve(N, A, MOD=1000000007):
    lcmv = lcm_array(A)
    bsum = 0
    for i in range(N):
        bsum += (lcmv // A[i])
        bsum %= MOD
    return bsum


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
def lcma(a,b):
  return a*b//gcd(a,b)
n=int(input())
a = list(map(int, input().split()))
lcm = a[0]
for i in a[1:]:
  lcm=lcma(lcm,i)
a=np.array(a)
a=lcm//a
ans=sum(a)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
A = list(map(int, input().split()))
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)

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

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

Submission status: Time Limit Exceeded

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

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

n = int(input())
A = [int(i) for i in input().split()]
k = lcm_list(A)
r = 0
for i in range(n):
    r += k//A[i]
    if r > 10**9+7:
        r %= 10**9+7
print(r)

Submission status: Time Limit Exceeded

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

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
z=lcm(A)

MOD=10**9+7
import numpy as np
A=np.array(A)
B=z//A

print(np.sum(B)%MOD)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
def lcm(x,y):
    return (x * y) // gcd(x, y)
MOD = 10**9+7


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

l = reduce(lcm,a)
ans=0
for i in range(n):
    ans+=l//a[i]%MOD
    ans%=MOD

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9+7

from functools import reduce # Python version 3.x

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

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

n = int(input())
den = [ int(i) for i in input().split() ]

lc = lcm(den)


total = 0
for i in den:
	if i!=0:
		total += (lc//i)
		total %= mod

print(total)

Submission status: Time Limit Exceeded

Solution code:

def main():
  import sys
  input = sys.stdin.readline

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

  from fractions import gcd
  from functools import reduce

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

  L = reduce(lcm, A)

  B = [None] * N

  for i in range(N):
    B[i] = (L // A[i]) % mod

  print(sum(B) % mod)

if __name__ == '__main__':
    main()