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: Accepted)

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Info{
	Info(ll arg_loc,ll arg_count){
		loc = arg_loc;
		count = arg_count;
	}
	ll loc,count;
};

#define SIZE 1000005

ll A[SIZE];
ll table[SIZE];
map<ll,ll> MAP;
bool is_prime[SIZE];
vector<Info> info[10005];


ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}


ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

int main(){

	for(int i = 0; i < SIZE; i++){

		is_prime[i] = true;
		table[i] = 0;
	}

	is_prime[0] = false;
	is_prime[1] = false;

	for(int i = 2; i < SIZE; i++){
		if(is_prime[i]){
			for(int k = 2*i;k < SIZE; k += i){
				is_prime[k] = false;
			}
		}
	}

	vector<ll> PRIME;
	for(int i = 2; i < SIZE; i++){
		if(is_prime[i]){
			MAP[i] = PRIME.size();
			PRIME.push_back(i);
		}
	}



	ll N;
	scanf("%lld",&N);

	for(int i = 0; i < N; i++){

		scanf("%lld",&A[i]);
		ll tmp = A[i];

		for(int k = 0; PRIME[k]*PRIME[k] <= A[i]; k++){

			if(tmp%PRIME[k] != 0)continue;

			ll count = 0;

			while(tmp > 0 && tmp%PRIME[k] == 0){
				count++;
				tmp /= PRIME[k];
			}
			table[k] = max(table[k],count);
			info[i].push_back(Info(k,count));

		}
		if(is_prime[tmp]){

			table[MAP[tmp]] = max(table[MAP[tmp]],1LL);
			info[i].push_back(Info(MAP[tmp],1));
		}
	}

	ll base = 1;
	for(int i = 0; i < PRIME.size(); i++){

		base *= mod_pow(PRIME[i],table[i],MOD);
		base %= MOD;
	}

	ll ans = 0;

	for(int i = 0; i < N; i++){

		ll tmp = base*mod_inverse(A[i],MOD);
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}