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 functools import reduce
from fractions import gcd

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

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())
aaa = get_nums_l()

g = lcm(aaa)

ans = 0
for a in aaa:
    ans += g//a
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

lcm = 1
for i in range(n):
    lcm = lcm * a[i] // fractions.gcd(lcm, 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 sys
input = sys.stdin.readline

from fractions import gcd


def lcd(x, y):
    g = gcd(x, y)
    return x * y // g


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

a.sort()

l = 1
for e in a:
    l = lcd(l, e)

ans = 0
for e in a:
    ans += l // e
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7

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

def gcd(x,y):
    while y:
        x,y = y,x%y
    return x

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

ans = 0

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

print(ans%MOD)

Submission status: Time Limit Exceeded

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

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()]
    sub = A[0]
    for i in A:
        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 collections import Counter

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

    def getPrimeFactors(x):
        anss = []
        for d in range(2, int(x**0.5)+1):
            while x%d == 0:
                anss.append(d)
                x //= d
        if x != 1:
            anss.append(x)
        return anss

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

    PFss = []
    Primes = set()
    for A in As:
        PFs = getPrimeFactors(A)
        cnt = Counter(PFs)
        PFss.append(cnt)
        Primes |= cnt.keys()

    lcmA = 1
    for P in Primes:
        num = 0
        for PFs in PFss:
            if PFs[P] > num:
                num = PFs[P]
        lcmA *= pow(P, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(10**6, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
from fractions import*
from functools import*
M=10**9+7
lcm=lambda x,y:x//gcd(x,y)*y
n,*a=map(int,open(0).read().split())
t=reduce(lcm,a)
c=0
for i in a:
    c+=t//i
    c%=M
print(c)

Submission status: Time Limit Exceeded

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

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

L = 1
for i in range(N):
    L = lcm(L, A[i])
ans = 0
for i in range(N):
    ans += L // A[i]
    ans %= M
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd


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()))
# 全て同じ値
if len(set(A)) == 1:
    print(N)
    exit()
l = least_common_multiple(A)
ans = 0
MOD = 10**9+7
for a in A:
    ans = (ans + l // a) % MOD
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_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

print(result)

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:
import fractions
from functools import reduce
import sys
input = sys.stdin.readline
MOD = 10**9+7

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

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

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

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

Submission status: Time Limit Exceeded

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

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

ans=0
#for i in range(n):
#    ans+=lcm//a[i]
a2 = list(map(lambda x: lcm //x , a))
print(sum(a2)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

N = int(input())
Ps = list(map(int,input().split(" ")))
MOD = 10 ** 9 + 7
g = 1

for p in Ps:
    g = g* p // fractions.gcd(g, p)
ans = 0
for p in Ps:
    ans += g//p
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a[1:]:
  lcm=lcma(lcm,i)
for i,s in enumerate(a):
  a[i]=lcm//s
ans=sum(a)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from fractions import gcd
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=list(map(int,input().split()))
    # n,*a=map(int,open(0).read().split())
    mod=10**9+7
    a.sort()
    b=a[-1]
    for i in a:
        if b%i!=0:
            b=b*i//gcd(b,i)
    ans=0
    print(sum(b//i%mod for i in a)%mod)    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

MOD=int(10**9+7)

g=A[0]
for i in range(1, N):
    g = (g*A[i])//fractions.gcd(g, A[i])
ans=0
for i in range(N):
  ans+=(g//A[i])%MOD
  ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
def lcm_n(nums):
    return functools.reduce(lcm, nums)

n = ni()
a = na()

a_lcm = lcm_n(a)
ans = 0
for ai in a:
    ans += a_lcm // ai
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
def gcd(x, y):
   while(y):
       x, y = y, x % y
   return x
def lcm(denominators):
    return reduce(lambda a,b: a*b // gcd(a,b), denominators)
def main():
    n = int(input())
    a = list(map(int, input().split()))

    l = lcm(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
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 *= k**(v - fs[k])
    ans += a
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

lcm = 1
for i,a in enumerate(As):
    lcm_tmp = lcm
    gcd_now = gcd(lcm_tmp,a)
    lcm = lcm_tmp*a//gcd_now

mod = 10**9+7
ans = 0
for a in As:
    ans += (lcm//a)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

MOD = int(1e9) + 7

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


class Inv:

    @classmethod
    def pow(cls, x: int, n: int) -> int:
        ret = 1
        while n > 0:
            if n % 2 == 1:
                ret = ret * x % MOD
            x = x * x % MOD
            n >>= 1
        return ret

    @classmethod
    def inv(cls, x: int) -> int:
        return cls.pow(x, MOD - 2)


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

v = functools.reduce(lcm, A)
ans = 0
for a in A:
    ans = (ans + v // a) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    from fractions import gcd
    from collections import Counter

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

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

    # A を圧縮
    c = Counter(A)
    values, counts = zip(*c.most_common())

    ans = 0
    for ci in range(len(values)):
        ans += (L // values[ci]) * counts[ci]
        ans %= INF
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def find_lcm(num1, num2): 
    if(num1>num2): 
        num = num1 
        den = num2 
    else: 
        num = num2 
        den = num1 
    rem = num % den 
    while(rem != 0): 
        num = den 
        den = rem 
        rem = num % den 
    gcd = den 
    lcm = (num1 * num2)/(gcd)
    return lcm

n = int(input())
l = list(map(int, input().split()))
lcm = 1 
  
for i in range(0, len(l)): 
    lcm = find_lcm(lcm, l[i])

ans = 0

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

print(int(ans % 1000000007))

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

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:
mod = 10**9+7
def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b )

def solve(arr):
	ans = 1
	for i in range(len(arr)):
		x = arr[i]
		for j in range(i+1,len(arr)):
			gd = gcd(arr[j], x)
			arr[j] = arr[j] // gd

		ans = ans * x
	return ans


n = int(input())
arr = [ int(i) for i in input().split() ]
orig = [ i for i in arr ]
lcm = solve(arr)
total = 0
for i in orig:
	total += lcm // i

print(total % mod)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def power(x, y):
   if y == 0:
       return 1
   elif y == 1:
       return x % mod
   elif y % 2 == 0:
       return power(x, y/2) ** 2 % mod
   else:
       return power(x, (y-1)/2) ** 2 * x % mod

def main():
	N = INT()
	A = LIST()

	tmp = A[0]

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

	B = [tmp//A[i] for i in range(N)]

	ans = 0
	for i in range(N):
		ans = (ans+B[i])%mod
	print(ans)

if __name__ == "__main__":
	main()

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 * b // gcd(a, b)

n = int(input())
li = list(map(int, input().split()))
ll = 1

for i in li :
    ll = lcm(ll, i)

mod = 1000000007

ans = 0
for i in li :
    ans = (ans + ll // i) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
from functools import reduce

input = sys.stdin.readline

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


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

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

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

index = lcm_list(A)

MOD = 10**9 + 7

ans = 0

for a in A:
    ans += (index//a) % MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

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

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

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:
from fractions import gcd
import sys
input = sys.stdin.readline

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

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:
import fractions


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

a=A[0]
for b in A:
    a = a /fractions.gcd(a, b)*b

count=0
for i in A:
    count+=a/i

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

if n == 1:
  print(1)
else:
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // int(fractions.gcd(lcm, a[i]))
  
  ans = 0
  for i in range(n):
    ans = (ans + lcm // a[i]) % PRIME
  
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

MOD = 10**9 + 7


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)


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


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


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

    AN_lcm = lcm_list(AN)

    ans = 0
    for A in AN:
        ans += AN_lcm * modinv(A, MOD)
        ans %= MOD

    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

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

n = int(input())
aaa = get_nums_l()

g = reduce(lcm, aaa)

ans = 0
for a in aaa:
    ans += g//a
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]

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

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    x = A[0]
    mod = 7 + 10**9
    for i in range(N):
        x = lcm(x, A[i])
    # print(x)
    ret = 0
    for i in range(N):
        ret += x // A[i]
        ret %= mod
    return ret


if __name__ == "__main__":
    print(main())

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:
from fractions import*
from functools import*
lcm=lambda x,y:x*y//gcd(x,y)
n,*a=map(int,open(0).read().split())
t=reduce(lcm,a)
c=0
M=10**9+7
for i in a:
    c+=t//i
    c%=M
print(c)

Submission status: Time Limit Exceeded

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

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

MOD = 10 ** 9 + 7
l = lcm(an)
sm = 0
for a in an:
  sm = (sm + l // a) % MOD
print(sm)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
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()))

ans = 0
MOD = 10**9 + 7
GCD = gcd_list(A)
LCM = lcm_list(A)//GCD


for a in A:
  a = a//GCD
  ans += LCM//a
  ans = ans%MOD
  
print(ans)

Submission status: Time Limit Exceeded

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

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

MOD = 1000000007
n = int(input())
a = [int(i) for i in input().split()]

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

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

Submission status: Time Limit Exceeded

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

mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
g = 1
for i in range(n):
    g = a[i] * g // gcd(a[i], g)
    #g %= mod

ans = 0
for i in range(n):
    ans += g * modinv(a[i])
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))


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)


y = lcm(*A)
MOD = 10 ** 9 + 7
ans = 0
for i, a in enumerate(A):
    ans += y // a
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Hello World program in Python
def gcd(a, b):
	if b == 0: return a
	return gcd(b, a%b)

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

A = []


N = int(raw_input())
A = map(int, raw_input().split())
l = 1
for x in A:
    l = lcm(l, x)
ans, mod = 0, 1000000007
for x in A:
    ans = (ans + l/x)
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

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

if N == 1:
    print(1)
    exit()


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


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


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

wa = 0
for i in range(N):
    wa += (saidaikoubaisuu // A[i])

print(wa % MOD)

Submission status: Time Limit Exceeded

Solution code:
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
B = int(input())
L = list(map(int, input().split()))
d=L[0]
mod=1000000007
for i in range(B):
  d=lcm(d,L[i])
ans=0
for i in range(B):
  ans+=d//L[i]
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    from fractions import gcd
    from collections import Counter

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

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

    # A を圧縮
    c = Counter(A)
    values, counts = zip(*c.most_common())

    ans = 0
    for ci in range(len(values)):
        ans += (L // values[ci]) * counts[ci] % INF
    print(ans % INF)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions

#最小公倍数
def union_lcm(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=num*lists[i]//fractions.gcd(num,lists[i])
        return num


#最大公約数
def union_gcd(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=fractions.gcd(num,lists[i])
        return num
mod=10**9+7   
n=int(input())
lists=list(map(int,input().split()))
a=union_lcm(lists)

c=0
for i in range(n):
    c+=a//lists[i]
    c=c%mod
print(c)

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 lcm(numbers):
    return reduce(lcm_base, numbers, 1)
    
a = lcm(arr)

ans = 0

for i in arr:
    ans+= (a//i)%1000000007
    if ans >=1000000007:
        ans % 1000000007
print(ans %(1000000000+7))

Submission status: Time Limit Exceeded

Solution code:
import fractions as math
from functools import reduce

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

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

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

N=int(input())
A=list(map(int,input().split()))
MOD=(10**9)+7
S=list(set(A))
LCM=lcm_list(S)
ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce


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

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

l = reduce(lcm, nums)

ans = 0
divs = [(l // x) % mod for x in nums]
ans = sum(divs) % mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a[1:]:
  lcm=lcma(lcm,i)
b=[]
for i in a:
  b.append(lcm//i)
ans=sum(b)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce


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

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

def llcm(l):
    return reduce(lcm, l)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    l = A[0]
    r = 0
    MOD = 10**9 + 7
    for i, a in enumerate(A):
        nl = lcm(l, a)
        r = (r * (nl // l) + nl // a) % MOD
        l = nl
    print(r)

main()

Submission status: Time Limit Exceeded

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

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

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

count=0
for a in A:
    count+=value//a
    count%=mod
print(count)

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

    l = 1
    for i in range(n):
        l = lcm(a[i], l)
    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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


from fractions import gcd


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, A):
    l = reduce(lambda x, y: x * y // gcd(x, y), A)
    M = Mod(10**9+7)
    ans = 0
    for a in A:
        ans = M.add(ans, l//a)

    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import fractions
lcm = 1
for ai in set(a):
    lcm = ai * lcm // fractions.gcd(ai, lcm)

ans = 0
for ai in a:
    ans += (lcm // ai)

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

Submission status: Time Limit Exceeded

Solution code:
import unittest
import functools


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 3, 4]), 13)

    def test_2(self):
        self.assertEqual(think([12, 12, 12, 12, 12]), 5)

    def test_3(self):
        self.assertEqual(think([1000000, 999999, 999998]), 996989508)

    def test_4(self):
        self.assertEqual(gcd(3, 2), 1)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    mode = 10 ** 9 + 7
    lcm_of_all_a = functools.reduce(lambda x, y: lcm(x, y), a, 1)
    b = map(lambda x: (lcm_of_all_a // x) % mode, a)
    return sum(b) % mode


def write(result):
    print(result)


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


def gcd(a, b):
    if a < b:
        return gcd(b, a)

    while True:
        if a % b == 0:
            return b
        a, b = b, a % b


if __name__ == '__main__':
    # unittest.main()
    solve()

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)


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

c = lcm_list(a)

b = []

for i in range(n):
    b.append(c//a[i])
print(sum(b)%(10**9+7))