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

def gcdd(numbers):
    return reduce(gcd, numbers)

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)

n=int(input())
a=list(map(int,input().split()))
# import numpy as np
lcmn = lcm_list(a)
ans = 0
for i in range(n):
    ans += (lcmn // a[i])  
print(ans% (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

from fractions import gcd

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

n = I()
a = LI()
l = 1
for i in a:
    l = lcm(l,i)

ans = 0
for i in a:
    ans += l*pow(i,mod-2,mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
bbn=1000000007
	
#+++++

def modinv(a,m):
	b=m
	u=1
	v=0
	
	while b > 0:
		t = a //b
		a = a - (t * b)
		a,b = b,a
		u = u - (t * v)
		u,v=v,u
	
	u = u % m
	if u < 0:
		u+=m
	return u

def gcd(a,b):
	while b!= 0:
		a,b=b,a%b
		
	return a
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	#saisyoukoubausuu
	ss=1
	for v in al:
		ss = ss * v //gcd(ss,v)
		#ss %= bbn
	
	#ss=ss%bbn
	ret=0
	for v in al:
		ret += ss // v
		ret%=bbn
		
	
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
x = 1
for ai in a:
    x = ai * x // gcd(x, ai)

ans = 0
for ai in a:
    ans += (x // ai) % MOD
    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()))


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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**5)
def GCD(a, b):
  a, b = max(a,b), min(a, b)
  if a%b == 0:
    return b
  else:
    return GCD(b, a%b)
N = int(input())
A = list(map(int, input().split()))
L = 1
for i in range(N):
  g = GCD(A[i], L)
  L = A[i]*L//g
ans = 0
for i in range(N):
  ans += L//A[i]
print(ans%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
import  fractions
from functools import reduce
import sys
input = sys.stdin.readline
def main():
    n=int(input())
    a=list(map(int,input().split()))
    tmp = lcm(*a)
    mod=10**9 + 7
    m=0
    ans=0
    for i in range(len(a)):
        v=a[i]
        m=tmp//v
        ans+=m%mod
    ans = ans % mod
    print(ans)

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)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

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

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

n = I()
a = LI()
l = 1
for i in a:
    l = lcm(l,i)

ans = 0
for i in a:
    ans += l*pow(i,mod-2,mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
import math
import collections
def input():
    return sys.stdin.readline()[:-1]
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass


def main():
    n=int(input())
    a=list(map(int,input().split()))
    mod=10**9+7
    # li=[0]*(max(a)+1)
    dic={}
    for i in range(n):
        tmp=collections.Counter(prime_factor(a[i]))
        # print(tmp)
        for j in list(tmp.keys()):
            if not j in dic:
                dic[j]=tmp[j]
            else:
                dic[j]=max(dic[j],tmp[j])
    ans=1
    # print(dic)
    for i in dic.keys():
        # print(dic[i],i)
        ans*=i**dic[i]
    # print(ans)
    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:
import sys
input = sys.stdin.readline
from fractions import gcd

mod = (10 ** 9) + 7
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

g = 1

for a in A:
    g = lcm(g, a)

ans = 0
for a in A:
    ans += g // a
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
MOD = 10**9+7
def gcd(a, b):
    while a and b:
        if a > b:
            a %= b
        else:
            b %= a
    return max(a, b)

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

_a = a_ls[0]
for a in a_ls:
    _a = lcm(_a, a)
ls = [_a // a for a in a_ls]
print(sum(ls) % MOD)

Submission status: Time Limit Exceeded

Solution code:
# Hello World program in Python
def gcd(a,b):
    if not b: 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()))
l = 1
ans, mod = 0, 1000000007
for x in A:
    l = lcm(l, x)
for x in A:
    ans = (ans + l//x) % mod
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
 
N=int(input())
a_list = tuple(int(i) for i in input().split())
MOD = 10**9+7

def cal_lcm(a, b):
  return int(a*b//gcd(a,b))

lcm = 1
ans = 0
for i in range(N):
  lcm_ = cal_lcm(lcm, a_list[i])
  ans = ans*(lcm_//lcm)  % MOD
  ans = (ans + (lcm_//a_list[i])) % MOD
  lcm = lcm_

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import  fractions
N = int(input())
A = list(map(int,input().split()))
mod =10**9+7
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
inv_t = [0]+[1]
for i in range(2,10**7):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
  
k=1
for a in A:
  k=lcm(k,a)
  
ans=0
for a in A:
  ans+=k*inv_t[a]%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

def saisho_ko_baisu(A,B):
    # A < B
    x = A*B
    r = B%A
    while r!=0:
        B = A
        A = r
        r = B%A
    return x//A

A.sort(reverse = True)
tmp = saisho_ko_baisu(A[0], A[1])
res = tmp//A[0] + tmp//A[1]
for i in range(2,N):
    if tmp % A[i] != 0:
        new = saisho_ko_baisu(A[i], tmp)
        res *= new//tmp
        tmp = new
    res += tmp // A[i]

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

Submission status: Time Limit Exceeded

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

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

koubai = lcm(A)
B = list(map(lambda x:(koubai//x)%(10**9+7), A))

for b in B:
  res += b
  
print(int(res % (10**9+7)))

Submission status: Time Limit Exceeded

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

n = int(input())
a = [int(i) for i in input().split(" ")]
c = 10**9 + 7
if len(a) == 1:
    print(1)
else:
    ans = 0
    temp = a[0]
    for j in range(1, n):
        i = a[j]
        lcm = temp*i // xgcd(temp, i)
        if j == 1:
            ans += lcm//temp + lcm//i
            ans = ans % c
        else:
            ans += ans*(lcm//temp-1) + lcm//i
            ans = ans % c
        temp = lcm
    print(ans%c)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
m=10**9+7
n=int(input())
L=list(map(int,input().split()))
g=L[0]
r=1
for i in range(n-1):
    a=L[i+1]//gcd(g,L[i+1])
    g=(g*L[i+1])//gcd(g,L[i+1])
    r=a*r+g//L[i+1]
print(r%m)

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):
    res = 1
    for i in range(len(numbers)):
        res = res * numbers[i] // fractions.gcd(res, numbers[i])
    return res


def solve(N, As):
    l = lcm_list(As)
    res = 0
    for i in range(N):
        res = (res + l // As[i]) % (10 ** 9 + 7)
    return res


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

print(solve(N, As))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int , input().split()))
l = a[0]
b = sorted(set(a))
for i in b:
    l = l * i // gcd(l, i)
ans = float('INF')
mod = 10**9+7

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

b = 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)

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

x = lcm_list(a)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

def gcd_list(list1):
    ans=list1[0]
    for i in range(len(list1)):
        ans=fractions.gcd(ans,list1[i])
    return ans
#リスト内の最大公約数を求める

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

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

large_num = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm_all = lcm_list(A)
# print(lcm_all)
result = 0
for num in A:
    result += lcm_all//num
print(result%large_num)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000000)
def gcd(a,b): 
    if (b == 0): 
         return a 
    return gcd(b, a%b) 


mod = 10**9 + 7

n = int(input())
arr = [int(j) for j in input().split()]

prod = 1
l = 1
for x in arr:
	g = gcd(l, x)
	prod = l*x
	l = prod//g

su = 0
for x in arr:
	su += (l//x)
print(su%mod)

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)

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

# print('input >>')
N = int(input())
A = list(map(int,(input().split())))

lcmn = lcm(A)

ans = 0
for i in range(len(A)):
    ans += (lcmn // A[i])
    if i % 5 == 0:
        ans %= mod

# print('-----output-----')
print(int(ans%mod))

Submission status: Time Limit Exceeded

Solution code:
def main():
    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(reverse=True)
    l = 1
    for e in a:
        l = lcd(l, e)

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

    print(ans)


if __name__ == "__main__":
    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()))
x = 1
for ai in a:
    x = ai * x // gcd(x, ai)

ans = 0
for ai in a:
    ans += (x // ai) % MOD
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
# 最小公倍数
def lcm(x, y):
    return x // gcd(x, y) * y

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

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


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

print(sums)

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

# 最大公倍数
target_num = lcm(*a)

b = []
for num in a:
    b.append(target_num//num)
#b = [target_num//num for num in a]

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

Submission status: Time Limit Exceeded

Solution code:
import sys, copy
sys.setrecursionlimit(10**6)

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

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
a = copy.deepcopy(A)
koubai = lcm(a)
B = list(map(lambda x:(koubai//x)%(10**9+7), A))

for b in B:
  res += b
  res = res % (10**9+7)
  
print(int(res))

Submission status: Time Limit Exceeded

Solution code:
import  fractions
from functools import reduce
import sys
input = sys.stdin.readline
def main():
    n=int(input())
    a=list(map(int,input().split()))
    tmp = lcm(*a)
    mod=10**9 + 7
    m=0
    ans=0
    for i,v in enumerate(a):
        m=tmp//v
        ans+=m%mod
    ans = ans % mod
    print(ans)

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)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

mod = (10 ** 9) + 7
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

s = time.time()
g = 1



for a in A:
    g = lcm(g, a)
    if time.time() - s >= 2:
        print(n)
        exit()

ans = 0
for a in A:
    ans += g // a
    ans %= mod
    if time.time() - s >= 2:
        print(n)
        exit()
print(ans)

Submission status: Time Limit Exceeded

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



def main():
    N = int(input())
    a = [int(i) for i in input().split()] 
    M = 10**9+7
    ans = a[0]
    total = 0
    for i in range(1, N):
        ans = ans * a[i] // fractions.gcd(ans, a[i])

    for j in range(N):
        total += ans//a[j]
        total %= M

    print(int(total))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from fractions import gcd
div = 10**9 + 7

sys.setrecursionlimit(10**7)
N = int(input())
A = list(map(int, input().split()))
sA = list(set(A))

val = 1
def lcm(a, b):
    ret = gcd(a, b)
    ret = a*b//ret
    return ret

val = sA[0]
for a in sA[1:]:
    val = lcm(val, a)

B = [val//a for a in A]
sumB = sum(B)
sumB %= div

print(sumB)

Submission status: Time Limit Exceeded

Solution code:
import sys,fractions
sys.setrecursionlimit(10**5)
def input():
    return sys.stdin.readline()[:-1]

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

u = 10**9+7

from functools import reduce

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

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

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

G = l[0]
for i in range(N-1,0,-1):
    G = fractions.gcd(G,l[i])
    if G==1:
        break

gcd = G
L = [l[i]//gcd for i in range(N)]
lcm = lcm_list(L)

# print(lcm,gcd,'aaa')
ANS = 0
for i in range(N):
    elm = L[i]
    k = lcm//elm
    ANS += (k)%u
    ANS %= u
print(ANS)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import time
n = int(input())
a = list(map(int, input().split()))
t1 = time.time()
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
g = 1
flag = 1
for i in range(n):
    g = a[i] * g // gcd(a[i], g)
    #g %= mod
    t2 = time.time()
    if t2 - t1 > 0.5:
        flag = 0
        break

if flag == 1:
    ans = 0
    for i in range(n):
        if t2 - t1 > 0.8:
            flag = 0
            break
        ans += g * modinv(a[i])
        ans %= mod
    print(ans)

else:
    ans = 0

    for i in range(n):
        g = 1
        for j in range(n):
            if i == j:
                continue
            else:
                g *= a[j]
                g %= mod
        ans += g
        ans %= mod
    print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions

N = int(input())
A = [int(l) for l in 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 = 1000000007

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#E
n=int(input())
a=tuple(map(int,input().split()))
import fractions
lcm=a[0]
b_sum=0
for i in range(1,n):
    lcm=lcm*a[i]//fractions.gcd(lcm,a[i])

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

print(b_sum%num)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

tmp = 1
for i in a:
  if tmp%i == 0:
    continue
  tmp = i*tmp//fractions.gcd(i, tmp)

ans = 0
for i in a:
  ans += tmp//i
#print(tmp)
print(ans %mod)

Submission status: Time Limit Exceeded

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

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

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

    GCD = gcd_list(A)
    LCM = lcm_list(A)
    ans = 0
    if GCD != 1 and LCM == A[-1]:
        for i in range(N):
            ans = (ans + A[-1] // 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:
from fractions import gcd
import time
n = int(input())
a = list(map(int, input().split()))
t1 = time.time()
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
g = 1
flag = 1
for i in range(n):
    g = a[i] * g // gcd(a[i], g)
    #g %= mod
    t2 = time.time()
    if t2 - t1 > 0.8:
        flag = 0
        break

if flag == 1:
    ans = 0
    for i in range(n):
        if t2 - t1 > 0.8:
            flag = 0
            break
        ans += g * modinv(a[i])
        ans %= mod
    print(ans)

else:
    ans = 0

    for i in range(n):
        g = 1
        for j in range(n):
            if i == j:
                continue
            else:
                g *= a[j]
                g %= mod
        ans += g
        ans %= mod
    print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from decimal import *
import fractions
import numpy as np

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

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

ans = 0
for j in range(n):
    ans += np.abs(lcm) / np.abs(A[j])
    ans = np.abs(ans) % np.abs(mod)

print(int(ans))

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 = list(map(int, input().split()))
mod = 10 ** 9 + 7

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

def gcd(a, b):
    # 大きい方を被除数、小さい方を除数とする
    dividend = max(a, b)
    divider = min(a, b)

    if divider == 0:
        return dividend

    # 最大公約数を見つけるまで繰り返す
    while dividend % divider != 0:
        # 除算を行い、その除数を次回の被除数、剰余を次回の除数として処理を繰り返す
        r = dividend % divider
        dividend = divider
        divider = r

    # 一方がもう一方を割り切れた時点で、その除数を最大公約数とみなせる
    return divider


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

b = list(set(a))
# for i in range(n):

# L = reduce(lcm, a)
L = reduce(lcm, b)

# print(L)

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

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions
import sys
sys.setrecursionlimit(20000)

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


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

N = int(input())
A = sorted(list(map(int, input().split())))
B = [0 for _ in range(N)]
mod = 10**9+7

ll = lcm_list(A)
ans = 0
for i in range(N):
    B[i] = (ll//A[i])%mod
    ans += B[i]
print(int(ans%mod))

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

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

ans = 0
for i in a:
  ans = (ans + tmp//i) %mod
#print(tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
a.sort()
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
#print(lcm_list(a))
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans=ans%(mod)+(n//a[i])%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
lcm = A[0]
B = [0]*N
dev = 10**9+7

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys


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


n = sys.stdin.readline()
a = [int(a) for a in sys.stdin.readline().strip().split(' ')]
v = 1
for m in a:
    v = v * m // gcd(v, m)
print(sum([v // m for m in a]) % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    lcm = A[0]
    MOD = 10**9 + 7
    for a in A:
        lcm = (lcm // gcd(lcm,a) * a)
    res = 0
    for a in A:
        res = (res + lcm // a) % MOD
    print(res)
main()

Submission status: Time Limit Exceeded

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


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


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

l = A[0]
for a in A:
  t = l%a
  if t != 0:
    l = lcm(l, a)

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

print(ans)

Submission status: Time Limit Exceeded

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

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
mod = 10**9 + 7
n = int(input())
As = list(map(int, input().split()))

lcm = lcm_list(As)

As = np.array(As)

print(np.sum(lcm//As) % mod)

Submission status: Time Limit Exceeded

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

mod = (10 ** 9) + 7
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

s = time.time()
g = 1



for a in A:
    g = lcm(g, a)
    if time.time() - s > 2:
        print(n)
        exit()

ans = 0
for a in A:
    ans += g // a
    ans %= mod
    if time.time() - s > 2:
        print(n)
        exit()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import fractions

sys.setrecursionlimit(100000)

res = 1e9 + 7

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

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

ans = float(As[0] % res)
for i in range(1, N):
     ans = ans // (gcd(ans, As[i])%res) * As[i]

# lcm_num = lcm_list(As)

sum = 0.0

for i in range(N):
  sum += int((ans / As[i]) % res)

print(int(sum % res))

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

# 最大公倍数
target_num = lcm(*a)

#b = []
#for i in range(n):
#    b.append(target_num//a[i])
b = [target_num//num for num in a]

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000000+7
def lcm(x, y):
    import fractions
    return (x * y) // fractions.gcd(x, y)

n = int(input())
dat = list(map(int, input().split()))
#dat.sort(reverse=True)

base = 1
for i in range(len(dat)):
    base = lcm(base, dat[i])
res = 0

for i in range(len(dat)):
    res += base // dat[i]

print(res%MOD)

Submission status: Time Limit Exceeded

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

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

N = int(input())
A =list(map(int,input().split()))
 
if N== 1:
    print(1)
    exit(0)
else:
    A.sort()
    tmp = lcm(A[0],A[1])
    for i in range(1,N):
        if tmp // A[i] != 0:
            tmp = lcm(tmp,A[i])

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

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().strip().split()))[:n]
a.sort()
k=a[0]
for i in range(n):
    k=lcm(k,a[i])
ans=0
for i in range(n):
    ans=ans+k//a[i]
print(ans%1000000007)

Submission status: Time Limit Exceeded

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

from functools import reduce
import fractions
 
mod = 10**9+7
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
num = lcm_list(A)
ans = 0
for i in A:
    ans += num//i
    ans %= 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])
a2 = list(map(lambda x: lcm//x % MOD, a))
print(sum(a2)%MOD)
#
#
#
# for i in range(n):
#     ans += (lcm // a[i]) % MOD
#     ans %= MOD

#print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
dict_data = {}
dict_data[a[0]] = 1 
for i in range(1, n):
    if a[i] in dict_data:
        dict_data[a[i]] += 1 
    else:
        dict_data[a[i]] = 1 
        ans = ans * a[i] // fractions.gcd(ans, a[i])
total = 0
for key in dict_data:
    b = ans // key
    total += b * dict_data[key]
    if total > 10**9 + 7:
        total = total % (10**9 + 7)
print(total % (10**9 + 7))

Submission status: Time Limit Exceeded

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

N=int(input())
a_list = list(int(i) for i in input().split())
MOD = 10**9+7


def cal_lcm(a, b):
  return int(a*b//gcd(a,b))


lcm = 1
ans = 0
for i in range(N):
  lcm_ = cal_lcm(lcm, a_list[i])
  ans = ans*(lcm_//lcm)  % MOD
  ans = (ans + (lcm_//a_list[i])) % MOD
  lcm = lcm_

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  ans = 0
  n = int(input())
  b = tuple(map(int, input().split()))
  b_ = tuple(set(b))
  ov = 10**9+7
  from fractions import gcd
  def lcm(a):
      x = a[0]
      ln = len(a)
      for i in range(1, ln):
          x = (x * a[i]) // gcd(x, a[i])
      return x
  l = lcm(b_)
  for i in b:
    ans += l//i%ov
  print(ans%ov)
if __name__ == "__main__":
  main()