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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 5001;

int bin_pow(int a, int b) {
	if (!b) return 1;
	if (b % 2) return a * bin_pow(a, b - 1) % MOD;
	int q = bin_pow(a, b / 2);
	return q * q % MOD;
}

vector<pair<int, int>> getDivs(int n) {
	vector<pair<int, int>> res;
	for (int d = 2; d * d <= n; d++) {
		if (n % d == 0) {
			int cnt = 0;
			while (n % d == 0) {
				n /= d;
				cnt++;
			}
			res.pb({ d, cnt });
		}
	}
	if (n > 1) res.pb({ n, 1 });
	return res;
}

void solve() {
	int n;
	cin >> n;
	int lcm = 1;
	vector<int> a(n);
	map<int, int> now;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		lcm = lcm * a[i] % MOD;
		vector<pair<int, int>> d = getDivs(a[i]);
		int g = 1;
		for (auto& p : d) {
			g = g * bin_pow(p.first, min(p.second, now[p.first])) % MOD;
		}
		lcm = lcm * bin_pow(g, MOD - 2) % MOD;
		for (auto& p : d) {
			now[p.first] += p.second;
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += lcm * bin_pow(a[i], MOD - 2) % MOD;
		ans %= MOD;
	}

	cout << ans;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	solve();
}