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

def main():
    input()
    aa = list(map(int, raw_input().split()))
    g = 1
    for a in aa:
        g = a * g // gcd(a, g)
    ans = 0
    for a in aa:
        ans = (ans + g // a) % (10 ** 9 + 7)
    print(ans)


main()

Submission status: Time Limit Exceeded

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

    def p(n):
        ret = defaultdict(int)
        d = 2
        m = int(n**0.5)
        while n > 1:
            if n % d == 0:
                ret[d] += 1
                n //= d
            else:
                d += 1
                if d > m:
                    ret[n] += 1
                    break
        return ret

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

    prime = defaultdict(int)
    p_list = []
    for a in A:
        pp = p(a)
        p_list.append(pp)
        for pr in pp.keys():
            prime[pr] = max(prime[pr], pp[pr])

    ans = 0
    for i, pp in enumerate(p_list):
        tmp = 1
        for pr in prime.keys():
            tmp = (tmp * pow(pr, prime[pr] - pp[pr], mod)) % mod
        ans = (ans + tmp)%mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = [int(x) for x in input().split(" ")]
def gcd(a, b):
  if b == 0:
    return a
  else: return gcd(b, a%b)

lcm = 1
for i in nums:
  lcm = lcm * i // gcd(lcm, i)

res = 0
for i in nums:
  res += (lcm // i) % 1000000007
print(res % 1000000007)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

from fractions import gcd

def p_prime(n): 
    prime = [2]
    for i in range(3,n+1):
        flag = 0
        for j in prime:
            if i%j == 0:
                flag = 1
                break
            if i**0.5 < j:
                break
        if flag == 0:
            prime.append(i)
    return prime

def soinsuu(M):
    a = {}
    prime = p_prime(int(M**0.5+1))
    for p in prime:
        count = 0
        while M%p ==0:
            count += 1
            M //= p
        if count > 0:
            a[p] = count
    if M != 1:
        a[M] = 1
    return a

from collections import defaultdict
AA = defaultdict(int)

for i in range(N):
    tmp = soinsuu(A[i])
    for j in tmp:
        AA[j] = max(AA[j],tmp[j])

BB = 1
for k in AA:
    BB *= pow(k,AA[k],mod)
    BB %= mod
    
ans = 0
for i in range(N):
    ans += BB*pow(A[i],mod-2,mod)
    ans %= mod

    
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
n = int(input())
a = 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)

l = lcm(a)
mod = 10**9+7
total = 0
for i in a:
    total += l//i
    total %= mod
print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


n = inp()
a = inpl()
g = 1
res = 0
for i in a:
    g = i*g//fractions.gcd(i,g)
for i in range(n):
    res += g//a[i]
    res %= mod
print(res)

Submission status: Time Limit Exceeded

Solution code:
def main():
  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
  
  L = A[0]
  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:
from fractions import gcd
import sys

input = sys.stdin.readline

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

MOD = 10 ** 9 + 7


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


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

res = 0
for a in A:
    res = (res + l // a) % MOD

print(res)

Submission status: Time Limit Exceeded

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

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

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

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

MOD = 1000000000 + 7
ans = 0
for a in A:
  ans = (ans + (now_lcm//a)) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def prime_decomposition(n):
    table = defaultdict(int)
    # table = [0] * (n + 1)

    i = 2
    while n % i == 0:
        n //= i
        table[i] += 1

    i = 3
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i] += 1
        i += 2

    if n > 1:
        table[n] += 1

    return table


def main():
    mod = 10 ** 9 + 7

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

    t = [prime_decomposition(x) for x in a]

    lcm_d = defaultdict(int)
    for pd in t:
        for prime, power in pd.items():
            lcm_d[prime] = max(lcm_d[prime], power)

    ret = 0
    for pd in t:
        curr = 1
        for prime, power in lcm_d.items():
            curr = (curr * pow(prime, power - pd[prime], mod)) % mod
        ret = (ret + curr) % mod

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
def lcm(x, y):
    if x % y == 0:
        return x
    return (x * y) // fractions.gcd(x, y)

n = int(input())
a = list(map(int, input().split()))
a.sort()
LCM = 1
for i in a[::-1]:
    LCM = lcm(LCM, i)
B = []
ans = 0
for i in a:
    B.append(LCM // i)
    tmp = LCM // i
    ans += tmp
    ans %= 10 ** 9 + 7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

MOD=10**9+7

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

N=int(input())
A=list(map(int, input().split()))
lcm=reduce(lcm_base, A, 1)
ans=0
for i in range(N):
  ans+=lcm//A[i]
print(ans%MOD)

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

DIV=10**9+7

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

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

L=1
for i in range(N):
  L=lcd(L,A[i])

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

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
MOD = 10**9+7

def lcm_n(l):
    rtn = l[0]
    for i in range(1,N):
        rtn = rtn * l[i] // fractions.gcd(rtn,l[i])
    return rtn

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

lcm = lcm_n(A)

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

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import fractions
def lcm(x, y):
    if x % y == 0:
        return x
    return (x * y) // fractions.gcd(x, y)

n = int(input())
a = list(map(int, input().split()))
LCM = 1
for i in a[::-1]:
    LCM = lcm(LCM, i)
B = []
ans = 0
for i in a:
    B.append(LCM // i)
    tmp = LCM // i
    ans += tmp
    ans %= 10 ** 9 + 7
print(ans)

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()))
l=1
ans=0
for i in range(n):
    l=lcm(a[i],l)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7


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

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

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 lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


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 // A
        ans %= 10**9 + 7

    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9 + 7
def gcd(a, b):
    while(b):
        a, b = b, a % b
    return a

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

n = int(input())
ar = [int(x) for x in input().split()]
L = ar[0]
for i in range(1, n):
    L = lcm(L, ar[i])

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

print(ans)

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

L = A[0]
for a in A:
  L = lcm(a,L)
ans = 0
for a in A:
  ans += L//a
  ans %= MOD
print(ans)

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

MOD = 10 ** 9 + 7


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


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

res = 0
for a in A:
    res = (res + l // a) % MOD

print(res)

Submission status: Time Limit Exceeded

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

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]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    g = 1
    for a in aa:
        g = a * g // gcd(a, g)
    ans = 0
    for a in aa:
        ans = (ans + g // a) % (10 ** 9 + 7)
    print(ans)


main()

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)


def solve():
    MOD = 10 ** 9 + 7
    N, *A = map(int, open(0).read().split())
    
    lcm_num = reduce(lcm, A)
    ans = 0
    for a in A:
        ans += lcm_num // a
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
l = 1
for i in a:
    l = i * l // (gcd(i, l))

cnt = 0
for i in a:
    cnt += l // i
    cnt %= mod
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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


ans = 0

dev = 10 ** 9 + 7

n = int(input())

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

z = lcm_list(a)


for i in a:
    ans += z // i
    ans = ans % dev

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

def lcm_list(numbers):
  return reduce(lcm, numbers, 1)         
         
lcm_ans = lcm_list(A)
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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


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

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split()))
b = []
tmp = a[0]
ans = 0

for i in range(1, n):
    tmp = tmp * a[i] // fractions.gcd(tmp, a[i])

for i in a:
    ans += tmp // i
    b.append(tmp // i)

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
MOD = 10 ** 9 + 7


def lcm(a, b):
    """
    aとbの最小公倍数を計算します。
    """
    return a * b // gcd(a, b)


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

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

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

Submission status: Time Limit Exceeded

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

n = int(input())
a = list(map(int, input().split()))
LCM = 1
for i in a:
    LCM = lcm(LCM, i)
B = []
ans = 0
for i in a:
    B.append(LCM // i)
    tmp = LCM // i
    ans += tmp
    ans %= 10 ** 9 + 7
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 10 ** 9 + 7

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

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

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

answer = 0
for a in A:
  answer = (answer + tmp // a) % MOD
print(answer)

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

N = INT()
A = LIST()

tmp = A[0]

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

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

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

Submission status: Time Limit Exceeded

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

primes = {}

for val in a:
    p = 2
    while p * p <= val:
        if val % p == 0:
            cnt = 0
            while val % p == 0:
                cnt += 1
                val //= p
            if p not in primes:
                primes[p] = cnt
            else:
                primes[p] = max(cnt, primes[p])
        p += 1

    if val != 1:
        if val not in primes:
            primes[val] = 1


lcm = 1
for p in primes:
    lcm = lcm * pow(p, primes[p], MOD) % MOD

   
def inv(x):
    return pow(x, MOD-2, MOD)

ans = 0
for val in a:
    ans += lcm * inv(val) % MOD
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()

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)

x = lcm_list(A)
y = [x//a for a in A]

ans = 0
for i in range(N):
    ans += y[i]
    ans %= 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)
n=int(input())
a=list(map(int,input().split()))
b=0
l=lcm_list(a)
for i in range(n):
    b+=l//a[i]
print(b%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from sys import stdin

def main():
    mod = 10**9 + 7
    input = stdin.readline

    N = int(input())
    A = input().split()
    num = 1
    for n in set(A):
        num = (num*int(n))//gcd(num,int(n))

    t = 0
    for n in A:
        t = (t + num//int(n)) % mod
    print(t)

if __name__ == "__main__":
    main()

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 lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
N = int(input())
A = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

Solution code:
# Pyhton3 program to find LCM of array
# without using GCD.

# Returns LCM of arr[0..n-1]
def LCM(arr, n):

	# Find the maximum value in arr[]
	max_num = 0;
	for i in range(n):
		if (max_num < arr[i]):
			max_num = arr[i];

	# Initialize result
	res = 1;

	# Find all factors that are present
	# in two or more array elements.
	x = 2; # Current factor.
	while (x <= max_num):

		# To store indexes of all array
		# elements that are divisible by x.
		indexes = [];
		for j in range(n):
			if (arr[j] % x == 0):
				indexes.append(j);

		# If there are 2 or more array
		# elements that are divisible by x.
		if (len(indexes) >= 2):

			# Reduce all array elements
			# divisible by x.
			for j in range(len(indexes)):
				arr[indexes[j]] = int(arr[indexes[j]] / x);

			res = res * x;
		else:
			x += 1;

	# Then multiply all reduced
	# array elements
	for i in range(n):
		res = res * arr[i];

	return res;

# Driver code
n = int(input())
arr = [ int(i) for i in input().split() ]
cpp = [ i for i in arr ]
get = LCM(arr, n)
total = 0
for i in cpp:
	if i != 0:
		total += (get//i)
print(total % (10**9+7) )

Submission status: Time Limit Exceeded

Solution code:
# -*- encoding: utf-8 -*-
import sys
from math import sqrt,log
from fractions import gcd  # python<=3.4

MOD=1000000007

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


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

el = 1
for ai in a:
    el = lcm(el, ai)

# print("el=", el)

sum = 0
for ai in a:
    bi = el // ai
    # print(bi, end=" ")
    sum += bi
    sum %= MOD
# print()
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import fractions as f
n=int(input())
a=list(map(int,input().split()))
cnt=a[0]
for i in range(n):
    cnt=(a[i]*cnt)//f.gcd(a[i],cnt)
ans=0
for i in range(n):
    ans+=cnt//a[i]
    ans=ans%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = 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)

lcm_a = 1

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

B = []

for i in range(N):
    B.append(lcm_a//A[i])

mod = int(1e9+7)

print(sum(B)%mod)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from random import randint
from collections import defaultdict
from itertools import accumulate
from fractions import gcd
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N = int(input())
A = inpl()
#N = 10**4
#A = [randint(0, 10**6) for _ in range(10**4)]

lcm = 1
for a in A:
    lcm = a * lcm // gcd(a, lcm)
ans = 0
for i in range(N):
    ans = (ans + lcm // 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()))


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


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

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

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
def GCD(x,y):
    x,y=max(x,y),min(x,y)
    if x%y==0:
        return y
    else:
        return GCD(y,x%y)

def LCM(x,y):
    return x*y//GCD(x,y)

# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

# factorial x!
def fact(x):
    global mod
    res=1
    for i in range(2,x+1):
        res=res*i%mod
    return res

# combination nCr
def combi(n,r):
    if r<0 or r>n:
        return 0
    else:
        return fact(n)*inv(fact(r))*inv(fact(n-r))%mod

# is a prime
def ispr(n):
    if n==1:
        return False
    elif n==2:
        return True
    elif n%2==0:
        return False
    else:
        k=3
        while k**2<=n:
            if n%k==0:
                return False
            else:
                k+=2
        return True

mod = 10 ** 9 + 7

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

l = 1
for Ai in A:
    l = LCM(l, Ai)
    # print(Ai, l)

ans = 0
for Ai in A:
    temp = l * inv(Ai) % mod
    # print(temp)
    ans = (ans + temp) % mod

print (ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction as F
from fractions import gcd

MOD = 10 ** 9 + 7

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

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

# B_1 = 1と仮定
b = [F(1, 1)]
for i in range(1, n):
    b.append(F(a[0], a[i]))

al_lcm = 1
for i in b:
    al_lcm = lcm(al_lcm, i.denominator)

res = 0
for i in b:
    res += i.numerator * pow(i.denominator, MOD - 2, MOD) % MOD * al_lcm % MOD

# lcmめっちゃ大きくなってそう

print(res % MOD)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from sys import stdin

def main():
    mod = 10**9 + 7
    input = stdin.readline

    N = int(input())
    A = input().split()
    num = 1
    for n in A:
        num = (num*int(n))//gcd(num,int(n))

    t = 0
    for n in A:
        t = (t + num//int(n)) % mod
    print(t)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

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

ans = 0
for i in A:
    ans = (ans + LCM // i) % (10 ** 9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

MOD = 10**9 + 7

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

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

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    l = llcm(A)
    r = 0
    for i in A:
        r = (r + (l // i)) % MOD
    print(r)

main()

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 lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
N = int(input())
A = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

read = sys.stdin.read


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


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

l = A[0]
g = A[0]
for i in A:
    g = gcd(l, i)
    l = l * i // g

answer = 0
for i in A:
    answer += l // i
    if answer >= mod:
        answer %= mod
print(answer)

Submission status: Time Limit Exceeded

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

N = int(input())
A = [int(x) for x in input().split()]
t = lcm(A)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import *
n,*a=map(int,open(0).read().split())
mod=10**9+7
b=a[0]
for i in a:
    b=b*i//gcd(b,i)
ans=0
for i in a:
    ans+=b//i
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

ans = 0
for a in A:
    ans += L // a
    ans %= INF
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

mod = 10**9 + 7

N = int(input())
A = input().split()
num = 1
for n in A:
    num = (num*int(n))//gcd(num,int(n))

t = 0
for n in A:
    t = (t + num//int(n)) % mod
print(t)

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 lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = [int(i) for i in input().split()]
l = lcm_list(a)
ans = 0
for i in range(n):
    ans += (l // a[i])
    ans = ans%(10**9+7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
from fractions import gcd
MOD = 10**9 + 7

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
import time
start = time.time()
n = int(input())
al = list(map(int,input().split()))

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


tmp = 1
for a in al:
    tmp = lcm(tmp, a)
    if time.time() - start > 1.9:
        print(sum(al))
        import sys
        sys.exit()

ans = 0
for a in al:
    ans += tmp // a
    ans %= 10**9 + 7
    if time.time() - start > 1.9:
        print(sum(al))
        import sys
        sys.exit()
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

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]
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n=int(input().rstrip())
a=input().rstrip().split(" ")
comon=1
for i in range(n):
    a[i]=int(a[i])
    comon = (comon*a[i]//fractions.gcd(comon, a[i]))

ans=0
MOD=1000000000+7
for i in range(n):
    ans=ans+comon//a[i]
    ans=ans%MOD

print(ans)

Submission status: Time Limit Exceeded

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

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

    return gcd(y % x, x)


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


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:
# Contest: AtCoder Beginner Contest 152 (https://atcoder.jp/contests/abc152)
# Problem: E: Flatten (https://atcoder.jp/contests/abc152/tasks/abc152_e)

def rint():
    return int(input())


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


from fractions import gcd
from functools import reduce
def lcm(a, b):
    return a * b // gcd(a, b)
n = rint()
a = rints()
l = reduce(lcm, a)
m = 10**9 + 7
print(sum(l // ai % m for ai in a) % m)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a
    
def lcm(m,n):
    return (m*n)//gcd(m,n)
for ai in A:
    pro=lcm(pro,ai)
for ai in A:
    count+=pro//ai
    count%=mod
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,m = [int(i) for i in readline().split()]
#d = [int(i) for i in readline().split()]
MOD = 10**9+7

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

#m = 1000000
#a = list(range(m,m+2000))

from fractions import gcd
m = a[0]
for i in a:
    m = m//gcd(m,i)*i

ans = 0
for i in a:
    ans += (m//i)%MOD

print(ans%MOD)