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

mod=10**9+7

n=int(input())

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

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

lcma=1

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

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

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

A.sort()

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

num = [0] * (10 ** 6 + 1)

ans = 0
for i in A:
  if num[i] == 0:
    v = l // i
    num[i] = v
  else:
    v = num[i]
  ans = (ans + v) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
lcm=A[0]

chk=True

for i in range(1,n):
  if lcm%A[i]!=0:
    lcm=lcm*A[i]//gcd(lcm,A[i])
  if lcm>10**100000:
    chk=False
    break

if chk:
  ans=0
  for i in range(n):
    ans=(ans+lcm//A[i])%mod
  print(ans)
else:
  ans=0
  mult=1
  for a in A:
    mult=(mult*a)%mod
  for a in A:
    ans=(ans+mult*pow(a,mod-2,mod))%mod
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7

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

def mod_inv(a,mod): # (x/a)%MODをしたい時は x%MOD * mod_inv(a,MOD)%MOD
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod


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

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

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

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

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
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 set(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:
import sys
input = sys.stdin.readline

N = int(input())
A = tuple(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 sys
from itertools import permutations, combinations
def input():
    return sys.stdin.readline()[:-1]
from collections import defaultdict, Counter
from math import factorial
import fractions
div = 10**9 + 7

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


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

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

sumB = 0
for a in A:
    sumB += val//a
    if sumB >= div:
        sumB %= div

print(sumB)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce, lru_cache


@lru_cache(maxsize=2**12)
def GCD(x, y):
    if y == 0:
        return x
    else:
        return GCD(y, x % y)


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:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
import functools
INF = float("inf")

MOD = 1000000007  # type: int


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


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


def solve(N: int, A: "List[int]"):

    # 最小公倍数
    lcm = 1
    for a in A:
        if lcm % a == 0:
            continue
        lcm = LCM(lcm, a)

    @functools.lru_cache(maxsize=None)
    def f(a):
        return (lcm//a) % MOD
    tot = 0
    for a in A:
        tot += f(a)
    print(tot % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

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]

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

	ans = 0
	for i in range(N):
		ans = (ans + (tmp*power(A[i], mod-2))%mod)%mod

	print(ans)

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

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

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

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

L = 1

for Ai in A:
    L = lcm(L, Ai)

ans = 0

for Ai in A:
    ans += L//Ai
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def s():
  n=int(input())
  l=list(map(int,input().split()))
  f=l[0]
  mod=10**9+7
  def gcd(s,d):
    return gcd(d,s%d) if d!=0 else s 
  for i in l:
    f=i*f//gcd(i,f)
  ans=0
  for iu in l:
    ans+=(f//iu)%mod
  print(ans%mod)
  
if __name__=="__main__":s()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

def factorize(n):
    """
    nの値を素因数分解し、素因数とその指数をtupleにまとめたリストを返す
    e.g.
    [(2, 2), (5, 1)]
    """
    b = 2
    fct = []
    while b * b <= n:
        cnt = 0
        while n % b == 0:
            cnt += 1
            n //= b
        if cnt > 0:
            fct.append((b, cnt))
        b += 1
    if n > 1:
        fct.append((n, 1))
    return fct


from collections import defaultdict

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

    d = defaultdict(int)
    for a in A:
        for num, f in factorize(a):
            d[num] = max(d[num], f)

    l = 1
    for num, f in d.items():
        l *= num ** f

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
B0 = A[0]
if N == 1:
    ans = 1
else:
    for a in A:
        B0 = (B0 * a) // fractions.gcd(B0,a)
    B0 = B0//A[0]
    ans = B0
    for i in range(1,N):
        ans += (A[0]*B0//A[i])
        ans = ans % (10**9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys


readline = sys.stdin.buffer.readline


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    C = 10**9 + 7

    d = collections.defaultdict(int)

    for a in A:
        B = factorization(a)
        for b in B:
            d[b[0]] = max(d[b[0]], b[1])
    e = 1
    for k in d.keys():
        e *= k**d[k]

    ans = 0
    for a in A:
        ans += (e // a)
        ans %= C
    print(ans)


main()

Submission status: Time Limit Exceeded

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

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

    return gcd(b, a % b)

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

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    mm = 1000000007
    lcm_a = a[0]

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

    ans = 0
    for i in range(0, n):
        ans = (ans + lcm_a//a[i]) % mm

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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


def pow_mod(x,n):
    if n==0:
        return 1
    
    K = 1
    while n>1:
        if n%2 != 0:
            K *= x
            K %= mod
        x *= x
        x %= mod
        n //= 2

    return K*x

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

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

Gcd = lcm(A[0],A[1])
ans = (Gcd//A[0]+Gcd//A[1])%mod
temp = Gcd//A[1]
#print(temp)

for i in range(1,N-1):
    Gcd = lcm(A[i],A[i+1])
    temp2 = Gcd//A[i]
    Gcd2 = lcm(temp,temp2)
    a = Gcd2//temp
    b = Gcd2//temp2

    temp = Gcd//A[i+1]*b

    a %= mod
    b %= mod
    ans *= a
    ans %= mod

    Gcd %= mod #注意
    c = A[i+1]
    c %= mod
    d = Gcd*pow_mod(c,mod-2)
    #d = Gcd//c
    d %= mod

    e = b*d%mod
    ans += e
    #ans += Gcd//A[i+1]*b
    ans %= mod


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

M = 10 ** 9 + 7

def calc_factors(n):
#	if n == 1:
#		return {1: 1}
	max = math.ceil(math.sqrt(n))
	data = {}
	x = 2
	while x <= max:
		if n % x == 0:
			if x in data:
				data[x] += 1
			else:
				data[x] = 1
			n //= x
			max = math.ceil(math.sqrt(n))
		else:
			x += 1
	if n != 1:
		if n in data:
			data[n] += 1
		else:
			data[n] = 1
	return data

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

total_factors = {}
factors_list = []

for A in A_list:
	factors = calc_factors(A)
	factors_list.append(factors)
	for factor, count in factors.items():
		if factor not in total_factors:
			total_factors[factor] = count
		elif total_factors[factor] < count:
			total_factors[factor] = count

total = 0
for A, factors in zip(A_list, factors_list):
	B = 1
	for factor, count in total_factors.items():
		if factor in factors:
			count -= factors[factor]
		for _ in range(count):
			B = (B * factor) % M
	total = (total + B) % M

print(total)

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

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

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)

mod = 10 ** 9 + 7

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

ans = 0
l = 1
for Ai in A:
    li = LCM(l, Ai)
    ans = (ans * (li // l)) % mod
    ans = (ans + li // Ai) % mod
    l = li

print (ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int , input().split()))
l = a[0]
for i in range(1, n):
    l = l * a[i] // gcd(l, a[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 sys #追加
sys.setrecursionlimit(500*500)

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

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

LCM = lcm(A)

ans = 0
for a in A:
    ans += LCM//a
    if (ans >= 1000000007):
        ans %= 1000000007

print(ans)

Submission status: Time Limit Exceeded

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

#print(lcm_list([27, 9, 3]))
# 27

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
mod = 1000000007

def add(a, b):
    return (a + b) % mod

n = int(input())
a = list(map(int,input().split()))
ans = a[0]
ans_ans = 0
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
for j in range(0, n):
  b = ans // a[j]
  ans_ans = add(ans_ans,b)
  
print(ans_ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
def main():
  _=input()
  a=tuple(map(int,input().split()))
  a1=a[0]
  fgcd=fractions.gcd
  for i in a:
    a1=(i*a1)//fgcd(i,a1)
  x=[a1//i for i in a]
  print(sum(x)%(10**9+7))
  
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
n=int(input())
mod=1000000007
ans=0
sum=0
s=[int(n) for n in input().split()]
for i in range(0, n):
    k=s[i]
    if i==0:
        ans=k
    else:
        u=ans
        ans = ((u * k) // gcd(u, k))
for i in range(0, n):
    sum=(sum+ans//(s[i]))%mod
print(sum)

Submission status: Time Limit Exceeded

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

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

if __name__=="__main__":
    main()

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


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

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#import math
#gcd = math.gcd
from fractions import gcd



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

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

ans = 0
MOD = 10**9+7
cur = 1
for a in A:
    cur =  lcm(cur,a)
    
for a in A:
    ans += cur//a
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr=[int (i) for i in input().split(" ")]

def GCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
   
def findlcm(arr, n) :
    ans = arr[0]
    for i in range(1,n):
        ans = (((arr[i] * ans))/(GCD(arr[i], ans))); 
    return ans


lcm = findlcm(arr, n)

sum = 0
MOD = 1000000007
for i in range(n):
    sum = (sum + (lcm/arr[i])%MOD)%MOD

print(int(sum))

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

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

N=int(input())
A=list(map(int,input().split()))
a_lcm=A[0]

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

result=0
for i in range(N):
    result+=a_lcm//A[i]
    result%=1000000007
print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
l = b[0]
for i in b[1:]:
    l = l * i // fractions.gcd(l,i)
mod = 10**9+7
total = 0
for i in a:
    total += l//i
    if total > mod:
        total %= mod
print(total)

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(1,N):
    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]
    ANS += (lcm//elm)
    ANS %= u
print(ANS)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
import functools
INF = float("inf")

MOD = 1000000007  # type: int


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


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


def solve(N: int, A: "List[int]"):

    # 最小公倍数
    lcm = 1
    for a in A:
        lcm = LCM(lcm, a)
    tot = 0

    @functools.lru_cache(maxsize=None)
    def f(a):
        return (lcm//a) % MOD
    tot = 0
    for a in A:
        tot += f(a)
    print(tot % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
from math import log,ceil
from fractions import gcd
mod = 10**9 + 7

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

def main():
    N = int(input())
    A  =list(map(int,input().split()))
    neko = 1
    for a in A:
        neko = lcm(neko,a)
    sm = 0
    for a in A:
        sm = (sm + neko // a)%mod
    print(sm)

    return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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:
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())
arr = [int(x) for x in input().split()] 
mod=1000000007
lc = arr[0]
for i in range(1, len(arr)): 
  	lc = lcm(lc,arr[i])
ans=0
for i in range(n):
    ans=ans+lc//arr[i]
    ans%=mod
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline


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

N=int(input())
a=list(map(int,input().split()))
calc=(lcm(a))  # 実行結果: 12

ans=0
for item in a:
    ans+=(calc)//item
    ans%=(10**9+7)

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

Submission status: Time Limit Exceeded

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

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

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

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
import fractions
div = 10**9 + 7

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

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

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

sumB = 0
for a in A:
    sumB += val//a
    sumB %= div

print(sumB)

Submission status: Time Limit Exceeded

Solution code:
import sys #追加
sys.setrecursionlimit(500*500)

dGCD = {}

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        temp = dGCD.get((x,a[i]))
        if (temp is None):
            temp = gcd(x, a[i])
            dGCD[(x,a[i])] = temp
        x = (x * a[i]) // temp
    return int(x)

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

LCM = lcm(A)

ans = 0
for a in A:
    ans += LCM//a
    ans %= 1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])
MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:

from sys import stdin

def gcd(x, y): 

	while(y): 
		x, y = y, x % y 

	return x

mod=10**9+7

n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))


lcm=a[0]

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



sm=0

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

print(sm)

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 ll(numbers):
  return reduce(lcm, numbers, 1)
n=int(input())
a=list(map(int,input().split()))
l=ll(a)
x=0
m=10**9+7
for i in range(n):
  x+=(l//a[i])%m
  x=x%m
print(x)

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 = {}
for i in range(1, n):
    if a[i] not in dict_data:
        dict_data[a[i]] = 1 
        ans = ans * a[i] // fractions.gcd(ans, a[i])
total = 0
for i in range(0, n):
    b = ans // a[i]
    total += b 
    if total > 10**9 + 7:
        total = total % (10**9 + 7)
print(total % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

n = int(input())
a = list(map(int, input().split()))
m = {}
def lcm(x, y):
    if x > y:
            x, y = y, x
    key = (x, y)
    if key in m:
        return m[key]
    res = x * y // gcd(x, y)
    m[key] = res
    return res

def rec(ls):
    if len(ls) == 1:
        return ls[0]
    elif len(ls) == 2:
        return lcm(ls[0], ls[1])
    return lcm(rec(ls[:len(ls) // 2]), rec(ls[len(ls) // 2:]))


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

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions

input = sys.stdin.readline

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



index = A[0]

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

MOD = 10**9 + 7

ans = 0

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

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 10 ** 9 + 7
    n = int(input())
    A = tuple(map(int, input().split()))
    gcd_v = reduce(lcm, A)

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
f=l[0]
mod=10**9+7
def gcd(s,d):
  return gcd(d,s%d) if d!=0 else s
for i in l:
  f=i*f//gcd(i,f)
ans=0
for iu in l:
  ans+=(f//iu)%mod
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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


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


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


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

for i in range(N):
    lcm = (lcm // fractions.gcd(lcm, A[i])) * 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 sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
#リストの最小公倍数
def lcm(a):    
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

N = ir()
A = lr()
A.sort()
if N == 1:
    print(1)
    exit()
MOD = 10 ** 9 + 7
l = []
first = A[0]
l = [x//gcd(x, first) for x in A[1:]]
x = lcm(l) #B[0]
answer = x%MOD

for i in range(1, N):
    answer += (first * x // A[i]) % MOD

print(answer%MOD)

Submission status: Time Limit Exceeded

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

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

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

def lcm_numbers(*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()))
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 fractions

n = int(input())
a = list(map(int,input().split()))
# lcm
x = a[0]
for  i in range(1,n):
    x = x * a[i] // fractions.gcd(x,a[i])
b = [x//a[i] for i in range(n)]
print(sum(b)%(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
from time import*
from fractions import*
start=time()
M=10**9+7
lcm=lambda x,y:x//gcd(x,y)*y
n,*a=map(int,open(0).read().split())
if n==1:
    print(1)
    exit()
s=a[0]
for t in a[1:]:
    if time()-start>1:
        s*=t
    else:
        s=lcm(s,t)
c=0
for i in a:
    c+=s//i
    c%=M
print(c)

Submission status: Time Limit Exceeded

Solution code:
import fractions as math

MOD = 10**9 + 7


def get_lcm(xs):
    ans = xs[0]
    for a in xs[1:]:
        ans = ans * a // math.gcd(ans, a)
    return ans


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

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

print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import sys, math

def input():
    return sys.stdin.readline()
def main():
    N = int(input())
    A = list(map(int,input().split()))
    MOD = 10**9 + 7
    t = A[0]
    def lcm(a,b):
        return a*b//gcd(a,b)
    for e in A:
        t = lcm(e,t)
    ans = 0
    for e in A:
        ans += t//e
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

M = 10 ** 9 + 7

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

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

lcm_ = A[0]
for a in A[1:]:
    lcm_ = lcm_ * a // gcd(lcm_, a)

ans = 0
for a in A:
    m = xgcd(a, M)
    ans = (ans + lcm_ * m) % M

print(ans)