Problem: 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).

Submission attempts (in order):
import numpy as np
from collections import Counter

def resolve():
    
    
    
    
    
    

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

    
    MX = int(10**6)
    L = np.zeros(MX+1)
    L[0] = -1
    L[1] = -1
    primes = []

    for i in range(2, MX+1):
        if L[i]:
            continue
        primes.append(i)
        L[i] = i
        for j in range(i*i, MX+1, i):
            if L[j] == 0:
                L[j] = i

    def factor(x: int):
        res = []
        while x != 1:
            prime = L[x] if L[x] != 0 else x
            res.append(prime)
            x /= prime
        return res

    max_e = {}
    for a in A:
        a = Counter(factor(a))
        for key, v in a.items():
            if not key in max_e:
                max_e[key] = v
            else:
                if v > max_e[key]:
                    max_e[key] = v
    # print(max_e)

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

    lcm = 1
    for key, v in max_e.items():
        lcm *= key ** v

    # print(max_e)
    # print(lcm)
    lcm %= MOD
    # print(lcm)

    ans = 0
    for i in range(N):
        b = lcm * modinv(A[i]) 
        ans += b

    print(int(ans % MOD))


def resolve_ref():
    from fractions import gcd
    
    mod = 10 ** 9 + 7
    
    N = int(input())
    A = list(map(int, input().split()))
    
    L = 1
    for a in A:
        L *= a // gcd(L, a)
    
    print(L)
    L %= mod
    print(L)
    
    print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

if __name__ == "__main__":
    resolve()

import numpy as np
from collections import Counter

def resolve():
    
    
    
    
    
    

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

    
    MX = int(10**6 + 5)
    L = np.zeros(MX+1)
    L[0] = -1
    L[1] = -1
    primes = []

    for i in range(2, MX+1):
        if L[i]:
            continue
        primes.append(i)
        for j in range(i+i, MX, i):
            if L[j] == 0:
                L[j] = i

    def factor(x: int):
        res = []
        while x != 1:
            prime = L[x] if L[x] != 0 else x
            res.append(prime)
            x /= prime
        return res

    max_e = {}
    for a in A:
        a = Counter(factor(a))
        for key, v in a.items():
            if not key in max_e:
                max_e[key] = v
            else:
                if v > max_e[key]:
                    max_e[key] = v
    # print(max_e)

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

    lcm = 1
    for key, v in max_e.items():
        lcm *= key ** v

    # print(max_e)
    # print(lcm)
    lcm %= MOD
    # print(lcm)

    ans = 0
    for i in range(N):
        b = lcm * modinv(A[i]) 
        ans += b

    print(int(ans % MOD))


def resolve_ref():
    from fractions import gcd
    
    mod = 10 ** 9 + 7
    
    N = int(input())
    A = list(map(int, input().split()))
    
    L = 1
    for a in A:
        L *= a // gcd(L, a)
    
    print(L)
    L %= mod
    print(L)
    
    print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

if __name__ == "__main__":
    resolve()

from collections import Counter

def resolve():
    
    
    
    
    
    

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

    
    MX = int(10**6)
    L = [0] * (MX + 1)
    L[0] = -1
    L[1] = -1
    primes = []

    for i in range(2, MX+1):
        if L[i]:
            continue
        primes.append(i)
        L[i] = i
        for j in range(i*i, MX+1, i):
            if L[j] == 0:
                L[j] = i

    def factor(x: int):
        res = []
        while x != 1:
            prime = L[x] if L[x] != 0 else x
            res.append(prime)
            x /= prime
            x = int(x)
        return res

    max_e = {}
    for a in A:
        a = Counter(factor(a))
        for key, v in a.items():
            if not key in max_e:
                max_e[key] = v
            else:
                if v > max_e[key]:
                    max_e[key] = v
    # print(max_e)

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

    lcm = 1
    for key, v in max_e.items():
        lcm *= key ** v

    # print(max_e)
    # print(lcm)
    lcm %= MOD
    # print(lcm)

    ans = 0
    for i in range(N):
        b = lcm * modinv(A[i]) 
        ans += b

    print(int(ans % MOD))


def resolve_ref():
    from fractions import gcd
    
    mod = 10 ** 9 + 7
    
    N = int(input())
    A = list(map(int, input().split()))
    
    L = 1
    for a in A:
        L *= a // gcd(L, a)
    
    print(L)
    L %= mod
    print(L)
    
    print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

if __name__ == "__main__":
    resolve()

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted