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: Time Limit Exceeded)

#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include <iostream>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;
ll k, arr[10004];
long long   GCD(long long   a, long long b) {
	if (b == 0)
		return a;
	else
		return GCD(b, a%b);
}
long long lcm(long long n)
{
	long long ans = 1;
	for (long long i = 0; i < k; i++) {
		//ans = (((ans * arr[i]) % inf) / (GCD(ans, arr[i]) % inf)) % inf;//   ans = (ans * arr[i])/(gcd(ans, arr[i])); 
		ll d = ((ans) * (arr[i]));
		ll k = GCD(min(ans, arr[i]), max(ans, arr[i]));

		ans = (d / k);
		//ans %= inf;
	}
	return ans;
}
vector <int>ans;
ll count1[10000005], count2[10000005];//3ddddd
void primefactor(ll n) {
	while (n % 2 == 0) {
		if (n % 2 == 0) {
			n /= 2;

			count2[2] = count2[2] + 1;
			if (count1[2] < count2[2])
				count1[2] = count2[2];
		}
	}
	for (int i = 3; i <= sqrt(n); i += 2) {//odd number
		while (n%i == 0) {
			n /= i;

			count2[i] = count2[i] + 1;
			if (count1[i] < count2[i])
				count1[i] = count2[i];
		}
	}
	if (n > 2) {

		count2[n] = count2[n] + 1;
		if (count1[n] < count2[n])
			count1[n] = count2[n];
	}
}
ll fp(ll a, ll n)
{
	if (n == 0)
		return 1;
	int p = fp(a, n / 2) %inf;
	p = (p * p) %inf;
	if (n & 1)
		p = (p * a) % inf;
	return p;
}
int main() {

	cin >> k;
	map<ll, ll>mp;
	set<ll>st;
	ll sum = 0;
	for (int i = 0; i < k; ++i) {
		cin >> arr[i];
		st.insert(arr[i]);
	}
	for (auto x : st) {
		memset(count2, 0, sizeof count2);
		primefactor(x);
	}
	for (int i = 0; i < 1000001; ++i) {
		if (count1[i] != 0) {
			ans.push_back(fp(i, count1[i]));
		}
	}
	ll lc = 1;
	for (int i = 0; i < ans.size(); ++i) {
		//lc = ((lc%inf)*(ans[i] % inf)) % inf;
		lc *= ans[i];
	}

	for (int i = 0; i < k; i++) {
		sum = (sum)%inf + ((lc / (arr[i]))%inf);
	}
	cout << sum%inf ;
	return 0;

}