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
import math
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)

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

common=lcm_list(A)
B=[]
for i in range(N):
    B.append(common//A[i])
print(sum(B)%a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

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

num = nums[0]
for i in range(N - 1):
    num = lcm(num, nums[i + 1])
# print(num)
print(sum([num // i for i in nums]) % (10 ** 9 + 7))

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)

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = lcm_list(A)
    ans = 0
    MOD = 10 ** 9 + 7
    for a in A:
        ans += D // a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def solve():
    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())
    As = list(map(int, input().split()))

    lcmA = reduce(lcm, As)
    #print('lcmA:', lcmA)

    ans = 0
    for A in As:
        ans += lcmA // A
        ans %= MOD

    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)


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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


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


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


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    N = get_input(int)
    A = get_inputs(int)

    # A.sort(reverse=True)
    l = reduce(lcm, A)
    B = [l // a for a in A]
    # print(B)
    ans = reduce(lambda x, y: (x + y) % MOD, B, 0)
    print(ans)


    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
lis = []
from functools import reduce
import fractions
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
lc = lcm(A)
for i in range(n):
    lis.append(lc//A[i])
print(sum(lis) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#a,b = map(int,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for i in range(N)]
#A = [list(map(int,input().split())) for i in range(N)]
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    gcda = gcd(a,b)
    return a*b//gcda
def lcmlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(lcm,lista)
mod = 10**9 + 7
lcml = lcmlist(A)
ans = 0
for i in A:
    ans = (ans + lcml//i)%mod
print(ans)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

def lcm(a,b):
	p = a*b
	g = gcd(a,b);
	return p//g
MOD = int(10**9+7)
n = int(input())
a = list(map(int,input().split()))
lc = a[0];
for i in range(1,n):
	lc = lcm(a[i],lc)
ans = 0
for i in range(n):
	ans += (lc//a[i])
	ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
mod = 10**9+7
def LCM(a,b):
    return a*b//fractions.gcd(a,b)

N=int(input())
A = [int(i) for i in input().split()]
curLCM = A[0]
for i in range(1,N):
    curLCM = LCM(curLCM,A[i])
ans = 0
for a in A:
    ans += curLCM//a 
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
A = list(map(int, input().split()))
lcm = A[0]
for a in A[1:]:
    lcm = lcm*a//gcd(a, lcm)
ans = 0
for a in A:
    ans = (ans+lcm//a)%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def compute_gcd(x, y):
   while(y):
       x, y = y, x % y
   return x
n = int(input())
l = list(map(int,input().split()))
num = 1
ans = 0
for i in range(n):
	num = (num*l[i])/(compute_gcd(num,l[i]))
for i in range(n):
	ans += (num/l[i])
print(int(ans%1000000007))

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


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


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


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    N = get_input(int)
    A = get_inputs(int)

    A.sort(reverse=True)
    l = reduce(lcm, A)
    B = [l // a for a in A]
    # print(B)
    ans = reduce(lambda x, y: (x + y) % MOD, B, 0)
    print(ans)


    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

N = int(input())
Ps = list(map(int,input().split(" ")))
MOD = 10 ** 9 + 7
g = 1
for p in Ps:
    g = lcm(g,p)
ans = 0
for p in Ps:
    ans += g//p
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

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

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

l = 1

for i in a:
  l = lcm(l, i)

s = 0

MOD = 10 ** 9 + 7

for i in a:
    s += l // i
    s %= MOD

print(s)

Submission status: Time Limit Exceeded

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

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
def main():

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

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

    b = 1
    for i in range(N):
        if b % A[i] != 0:
            g = gcd(b, A[i])
            b = b * A[i] // g

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


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

Submission status: Time Limit Exceeded

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


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


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


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


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


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

    return


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


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


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


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

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


# F
def F():
    return


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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

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


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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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:
MOD=10**9+7
import fractions
N=int(input())
if N==1:
  A=int(input())
  print(1)
  exit()
  
A=list(map(int, input().split()))

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

tmp=f(A[0], A[1])
for i in range(2, N):
  tmp=f(tmp, A[i])
  
out=0
print(sum([(tmp//A[i])%MOD for i in range(N)])%MOD)

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):
    x=lcm(a[i],l)//l
    ans*=x
    l=lcm(a[i],l)
    ans+=(l//a[i])%(10**9+7)

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

Submission status: Time Limit Exceeded

Solution code:
import array

n= int(input())

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

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

prime_map, prim = calculate_prime()

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

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

#print(lcm)
result = 0

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

print(result)

Submission status: Time Limit Exceeded

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


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


MOD = 1000000007

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

l = 1
for i in range(n):
    l = LCM(l, a[i])

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

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

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):
	p = a*b
	g = gcd(a,b);
	return p//g
MOD = int(10**9+7)
n = int(input())
a = list(map(int,input().split()))
lc = a[0];
for i in range(n):
	lc = lcm(a[i],lc)
ans = 0
for i in range(n):
	ans += (lc//a[i])
	ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in B:
  ans = (ans + i) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
def prime_factorization(n):
    r={}
    for i in range(2,int(n**.5)+1):
        num=0
        while(True):
            x,y=divmod(n,i)
            if y!=0:
                break
            n=x
            num+=1
        if num>0:
            r[i]=num
    if n>1:
        r[n]=1
    return r
mod=10**9+7
def mul(a,b):
    return ((a%mod)*(b%mod))%mod
def div(a,b):
    return mul(a,pow(b,mod-2,mod))
from collections import defaultdict
d=defaultdict(int)
for a in A:
    r=prime_factorization(a)
    for k,v in r.items():
        d[k]=max(d[k],v)
X=1
for k,v in d.items():
    X=X*pow(k,v,mod)%mod
r=0
for a in A:
    r=(r+div(X,a))%mod
print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def factorize(a):
    factors = {}
    v = a
    p = 2
    while p*p<=a:
        if v%p==0: factors[p] = 0
        while v%p==0:
            v//=p
            factors[p]+=1
        p+=1
    if v>1: factors[v] = 1
    return factors

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

# calc lcm
lcm = {}
for a in A:
    factors_a = factorize(a)
    for k, v in factors_a.items():
        if k not in lcm or lcm[k]<v: lcm[k] = v

C = 1
for k, v in lcm.items():
    C *= pow(k, v, mod)
    C %= mod

ans = 0
for a in A:
    ans += C * pow(a, mod-2, mod)
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        x, y = y, x % y
    return x

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

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

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

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

p = lcm_list(al)

ans = 0

for a in al:
    ans += p // a
    ans %= 10**9 + 7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
mod = 10**9+7

# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

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

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m=mod):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

import sys
input = sys.stdin.readline


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

dic = {}
for a in A:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

lcm = 1
for num, count in dic.items():
    lcm *= pow(num, count, mod)

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

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

Submission status: Time Limit Exceeded

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

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

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

lcmA = reduce(lcm, As)
#print('lcmA:', lcmA)

ans = 0
for A in As:
    ans += lcmA // A
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

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)

BASE = 10**9 + 7

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

MOD = 10**9+7

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


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


N = int(input())
A = list(map(int, input().split()))
tmp = lcm(A)
ans = 0
for a in A:
    ans = (ans + tmp // a)%MOD
print(ans)

Submission status: Time Limit Exceeded

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


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


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

ans = 0
prev = A[0]
for a in A:
    l = lcm(prev, a)
    factor = l // prev
    ans = (ans * factor + l // a) % mod
    prev = l
print(ans)

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 lcm(x, y):
    g = gcd(x, y)
    return x * y // g

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import math
import fractions

MOD = 10 ** 9 + 7

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

lcm = 1

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import fractions
mod = 10**9+7
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0

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

l = 1
for i in A:
    l = lcm(l,i)
    
for j in A:
    ans += (l//j)
    ans %= mod
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
l = 1
res = 0
for x in a: l = x * l // gcd(x, l)
for x in a:
  res += l // x
  res %= mod
print(res)

Submission status: Time Limit Exceeded

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

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

    X = 1
    for a in A:
        g = gcd(X, a)
        X = (X * a) // g
    ans = 0
    for a in A:
        ans = (ans + X // a)%mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


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


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


MOD = 10**9 + 7

n = ri()
ls = ril()
if n == 1:
    print(1)
    exit()

x = ls[0]
for i in range(1, n):
    x = lcm(x, ls[i])
ds = [x // y for y in ls]
print(sum(ds) % MOD)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import fractions
import numpy as np

mod = 10**9+7

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

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

np_a = np.array(a)
ans = div//np_a
print(np.sum(ans)%mod)

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
import numpy as np
A=np.array(A,dtype=int)
ans=np.sum(L//A)
ans%=DIV

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

LARGE = 10 ** 9 + 7


def solve(n, a_list):

    # inverse
    res = 0
    for i in range(n):
        res += pow(a_list[i], LARGE - 2, LARGE)
        res %= LARGE

    # primes
    p_candidate_arr = np.ones(10 ** 3, dtype=np.int)
    p_candidate_arr[:2] = 0
    for p in range(2, 10 ** 3):
        if p_candidate_arr[p]:
            p_candidate_arr[p * p::p] = 0
    primes_1000 = np.where(p_candidate_arr == 1)[0]

    lcm = 1
    for p in primes_1000:
        r_max = 0
        for i in range(n):
            r = 0
            while a_list[i] % p == 0:
                r += 1
                a_list[i] = a_list[i] // p
            r_max = max(r_max, r)
        lcm *= pow(int(p), r_max, LARGE)
        lcm %= LARGE

    for q in np.unique(a_list):
        lcm *= q
        lcm %= LARGE

    return res * lcm % LARGE


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(3, [2, 3, 4]) == 13
    assert solve(5, [12, 12, 12, 12, 12]) == 5
    assert solve(3, [1000000, 999999, 999998]) == 996989508


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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  big,sml = lcm,a[i]
  while sml != 0:
    big,sml = sml,big%sml
  lcm *= a[i] // big
ans = 0
mod = 10 ** 9 + 7
for i in range(n):
  tmp = lcm // a[i]
  tmp %= mod
  ans += tmp
  ans %= mod
print(ans)
#print(lcm)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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

#最小公倍数でよいか？
#全てのjについてAiBiはAjで割り切れる
#計算時間は？
from fractions import gcd
mod =10**9+7
def lcd(x,y):
    g = gcd(x,y)
    return x*y//g

ag = 1
for i in range(n):
    ag = lcd(ag,a[i])

ans = 0

for i in range(n):
    ans += ag//a[i]

ans %=mod

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
def main():

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

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

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

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

    return sum(B) % mod

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    from fractions import gcd
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=list(map(int,input().split()))
    # n,*a=map(int,open(0).read().split())
    mod=10**9+7
    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)    
    # print(sum(b//i%mod for i in a)%mod)    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
lcm = lambda x,y: x*y//gcd(x,y)
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
    b = lcm(a, p)
    ans = (ans * (b // p) % MOD + (b // a))%MOD
    p = b
print(ans)

Submission status: Time Limit Exceeded

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

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

def gcd(a, b):
    # return a if b == 0 else gcd(b, a % b)
    while b > 0:
        c = a % b
        a = b
        b = c
    return int(a)

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

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

ans = 0
MOD = int(1e9 + 7)
for i in range(N):
    ans += int(l // A[i])
    ans %= MOD

print(ans)

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)

L = reduce(lcm, a)

# print(L)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import random
from fractions import gcd
lim=10**9+7
def lcm(a):
    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=random.sample(list(range(1, 10**6)), k=10**4)
A=[int(i) for i in input().split()]
Z=lcm(A)
ans=0
for a in A:
    ans =(ans+Z//a) % lim
print(ans)

Submission status: Time Limit Exceeded

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

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

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