Buggy python submission (verdict: Runtime Error):
class Sieve:
    """区間[2,n]の値を素因数分解する"""

    def __init__(self, n=1):
        primes = []
        f = [0] * (n + 1)
        f[0] = f[1] = -1
        for i in range(2, n + 1):  # 素数を探す
            if f[i]: continue
            primes.append(i)
            f[i] = i  # 素数には自身を代入
            for j in range(i * i, n + 1, i):  # 合成数に素因数を書き込む
                if not f[j]:
                    f[j] = i  # 最小の素因数を代入
        self.primes = primes
        self.f = f

    def is_prime(self, x) -> bool:  # 素数判定
        return self.f[x] == x

    def factor_list(self, x) -> list:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        fl = self.factor_list(x)
        if not fl: return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res


def main():
    from collections import defaultdict

    MOD = 10 ** 9 + 7
    A_MX = 10 ** 6

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

    s = Sieve(n=A_MX)

    lcm = defaultdict(int)

    factors = []
    for x in a:
        f = [0] * (A_MX + 1)
        for prime, cnt in s.factor(x):
            lcm[prime] = max(lcm[prime], cnt)
            f[prime] = cnt
        factors.append(f)

    ans = 0
    for f in factors:
        t = 1
        for prime, cnt in lcm.items():
            power = max(0, cnt - f[prime])
            t *= pow(prime, power, MOD)
            t %= MOD
        ans += t
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
class Sieve:
    """区間[2,n]の値を素因数分解する"""

    def __init__(self, n=1):
        primes = []
        f = [0] * (n + 1)
        f[0] = f[1] = -1
        for i in range(2, n + 1):  # 素数を探す
            if f[i]: continue
            primes.append(i)
            f[i] = i  # 素数には自身を代入
            for j in range(i * i, n + 1, i):  # 合成数に素因数を書き込む
                if not f[j]:
                    f[j] = i  # 最小の素因数を代入
        self.primes = primes
        self.f = f

    def is_prime(self, x) -> bool:  # 素数判定
        return self.f[x] == x

    def factor_list(self, x) -> list:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        fl = self.factor_list(x)
        if not fl: return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res


def main():
    from collections import defaultdict

    MOD = 10 ** 9 + 7
    A_MX = 10 ** 6

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

    s = Sieve(n=A_MX)

    lcm = defaultdict(int)

    factors = []
    for x in a:
        f = defaultdict(int)
        for prime, cnt in s.factor(x):
            lcm[prime] = max(lcm[prime], cnt)
            f[prime] = cnt
        factors.append(f)

    ans = 0
    for f in factors:
        t = 1
        for prime, cnt in lcm.items():
            power = max(0, cnt - f[prime])
            t *= pow(prime, power, MOD)
            t %= MOD
        ans += t
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


def prime_decomposition(n):
    table = defaultdict(int)

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

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

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

    return table


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

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

    lcm_d = defaultdict(int)
    pds = []
    for x in a:
        pd = prime_decomposition(x)
        pds.append(pd)
        for prime, power in pd.items():
            lcm_d[prime] = max(lcm_d[prime], power)

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

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + L * pow(x, mod - 2, mod)) % mod
    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


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

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

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

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

    return table


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

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

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

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

    gcd_d = defaultdict(lambda: mod - 1)
    for pd in t:
        for prime, power in lcm_d.items():
            pd[prime] = power - pd[prime]
            gcd_d[prime] = min(pd[prime], gcd_d[prime])

    gcd_ = 1
    for prime, power in gcd_d.items():
        gcd_ = (gcd_ * pow(prime, power, mod)) % mod

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

    ret = ret * gcd_ % mod

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


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

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

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

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

    return table


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

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

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

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

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

    print(ret)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from functools import reduce

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

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

    mod = 10 ** 9 + 7

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

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()