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 JavaScript (Node.js 12.16.1) (judge verdict: Wrong Answer)

function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let C = 1e9 + 7;
	let C2 = 1e5;
	let N = parseInt(input[0][0], 10);
	let v_A = input[1].map(e => parseInt(e, 10));

	let v_TF = Array.from({length: 1e3}, () => true);
	for (let i = 2;  i <= 1e3 / 2; i++){
		for (let j = 2; j <= 1e3 / i; j++){
			v_TF[i * j - 1] = false;
		}
	}
	let v_prime = [];
	for (let i = 1; i < v_TF.length; i++){
		if (v_TF[i]) v_prime.push(i + 1);
	}

	//calculate saishokobaisu
	let v_howManyTimes = Array.from({length: v_prime.length}, () => 0);
	let tmp;
	let arr_soinsu = Array.from({length: N}, () => []);
	whole_loop:
	for (let i = 0; i < N; i ++){
		tmp =  v_A[i];
		for (let j = 0; j < v_prime.length; j++){
			let count = 0;
			while (tmp % v_prime[j] === 0){
				tmp /= v_prime[j];
				count ++;
			}
			arr_soinsu[i][j] = count;
			v_howManyTimes[j] = Math.max(v_howManyTimes[j], count);
			if (tmp === 1) continue whole_loop;
		}
	}

	let P = 1;
	for (let i = 0; i < v_prime.length; i ++){
		for (let j = 1; j <= v_howManyTimes[i]; j ++){
			P = kakeruR(P, v_prime[i], C, C2);
		}
	}

	//calculate inverse
	let v_INV = INV(1e3, C, C2);

	//calculate ans

	let ans = 0;
	for (let i = 0; i < N; i ++){
		tmp = P;
		for (let j = 0; j < v_prime.length; j ++){
			if (arr_soinsu[i][j] !== 0){
				for (let k = 1; k <= arr_soinsu[i][j]; k ++){
					tmp = kakeruR(tmp, v_INV[v_prime[j]], C, C2);
				}
			}
		}
		ans += tmp;
		ans %= C;
	}
	console.log(ans); 
}

function  INV(n, MOD, C2) { //return [0!^-1, 1!^-1, 2!^-1, ..., n!^-1]
    let inv;
    inv = [0,1];
    for (var i = 2; i <= n; i++){
        inv.push(MOD - kakeruR(inv[MOD%i], (MOD / i | 0), MOD, C2) % MOD);
    }
    return inv;
}

function kakeruR(a, b, C, C2){
    var tmpQ, tmpR, ans;
    tmpQ = (b / C2 | 0);
    tmpR = b - (tmpQ * C2);
    ans = (a * tmpQ % C) * C2 % C + (a * tmpR);
    ans %= C;
    return ans;
}

// function saishoKobai(x, y){
//     if (x < y) [x, y] = [y, x];
//     var tmp1 = x;
//     var tmp2 = y;
//     while (tmp2 != 0){
//         [tmp1, tmp2] = [tmp2, tmp1 % tmp2];
//     }
//     return (BigInt(x) * BigInt(y) / BigInt(tmp1));
// }



Main(require("fs").readFileSync("/dev/stdin", "utf8"));