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: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define LLI long long int
#define REP(i, n) for(LLI i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(LLI i = s, i##_l = (e); i < i##_l; i++)
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

std::vector<bool> p;

LLI mpow(LLI a, LLI b) {
    LLI ret = 1;
    REP(i, b) {
        ret *= a;
    }
    return ret;
}

void sieve(size_t max) {
    if(max + 1 > p.size()) {      // resizeで要素数が減らないように
        p.resize(max + 1, true);  // pに必要な要素数を確保
    }
    p[0] = false;  // 0は素数ではない
    p[1] = false;  // 1は素数ではない

    for(size_t i = 0; i <= max; ++i)              // 0からmaxまで全て調べる
        if(p[i])                                  // iが素数ならば
            for(size_t j = i + 1; j <= max; ++j)  //i+1からmaxまで全て調べる
                if(j % i == 0)                    // iの倍数は
                    p[j] = false;                 // 素数ではない
}

int main() {
    cout << fixed << setprecision(10);
    LLI n;
    cin >> n;

    sieve(10000);

    vector<LLI> list;
    REP(i, 10000) {
        if(p[i]) {
            list.push_back(i);
        }
    }

    vector<LLI> a(n);
    vector<LLI> pc(1000001);
    REP(i, n) {
        cin >> a[i];

        // 素因数分解
        LLI t = a[i];

        for(LLI pn : list) {
            if(t == 1) break;
            LLI tc = 0;
            while(t % pn == 0) {
                t /= pn;
                tc++;
            }
            chmax(pc[pn], tc);
        }
        if(t != 1) {
            chmax(pc[t], 1);
        }
    }

    LLI mnum = 1;
    REP(i, 1000001) {
        //if(pc[i]) cout << i << ";" << pc[i] << endl;
        mnum *= mpow(i, pc[i]);
        if(1000000 < mnum) mnum = 1 / 0;
    }

    //cout << mnum << endl;
    LLI ans = 0;
    REP(i, n) {
        ans += mnum / a[i];
        ans %= MOD;
    }
    cout << ans;
    return 0;
}