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)

/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

ll modpow(ll f, ll s){
    ll res = 1;
    for(int i = 0; i < s; i++){
        res *= f;
        res %= MOD;
    }
    return res;
}

int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll maxa = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        maxa = max(maxa, a[i]);
    }

    vector<vector<pair<ll,ll>>> primefact(n);

    map<ll,ll> ma;

    for(int i = 0; i < n; i++){
        ll tmp = a[i];
        for(int j = 2; j * j <= a[i]; j++){
            ll cnt = 0;
            while(tmp % j == 0){
                cnt++;
                tmp /= j;
            }
            primefact[i].push_back(make_pair(j, cnt));
        }

        if(tmp == a[i]){
            primefact[i].push_back(make_pair(a[i], 1));
        }

        for(int j = 0; j < primefact[i].size(); j++){
            ma[primefact[i][j].first] = max(ma[primefact[i][j].first], primefact[i][j].second);
        }

    }

  
    // for(int i = 2; i <= maxa; i++){
    //     ll tmpma = 0;
    //     for(int j = 0; j < primefact.size(); j++){
    //         tmpma = max(tmpma, primefact[j][i]);
    //     }
    //     ma[i] = tmpma;
    // }
    ll totallcm = 1;
    for(auto &i : ma){
        totallcm *= modpow(i.first, i.second);
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll x, y;
        ll g = extGCD(a[i], MOD, x, y);
        while(x < 0) x += MOD;
        ans += (totallcm * x) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

}