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

Solution in PyPy3 (2.4.0) (judge verdict: Time Limit Exceeded)

#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    def gen_primes2(upper_bound):
        upper_bound += 1
        P = [True] * upper_bound
        P[0] = P[1] = False
        for i in range(4,upper_bound,2):
            P[i] = False
        for i in range(3,int(upper_bound**0.5),2):
            if P[i]:
                for j in range(i**2,upper_bound,i):
                    P[j] = False
        res = []
        for i in range(upper_bound):
            if P[i]:
                res.append(i)
        return res

    N = II()
    A = LMIIS()
    upper_bound = max(A)
    primes = gen_primes2(upper_bound)
    LCMP = [0]*len(primes)
    for i in range(N):
        a = A[i]
        for j in range(len(primes)):
            t = 0
            while a % primes[j] == 0:
                a //= primes[j]
                t += 1
            LCMP[j] = max(t, LCMP[j])
            if a == 1:
                break
    lcm = 1
    for i in range(len(primes)):
        lcm = lcm * pow(primes[i],LCMP[i],MOD) % MOD



    inv = [0, 1]
    for i in range(2, upper_bound+1):
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)

    ans = 0
    for a in A:
        # ans += lcm * pow(a, MOD-2, MOD)
        ans += lcm * inv[a]
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()