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 <bits/stdc++.h> 
using namespace std;

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define FOR(n) for(int64_t i=0;i<n;i++)

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    FOR(n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}



palivec plcm(const palivec &x, const palivec &y){
    palivec l;
    ll nx = x.size();
    ll ny = y.size();
    ll i=0, j=0;
    if(nx==0) return y;
    if(ny==0) return x;
    while((i<=nx-1) && (j<=ny-1)){
        if(x[i].first == y[j].first) {
            l.pb(pal(x[i].first, max(x[i].second, y[j].second)));
            i++;
            j++;
        }
        else if(x[i].first < y[j].first) {
            l.pb(x[i]);
            i++;
        }
        else {
            l.pb(y[j]);
            j++;
        }
    }
    if(i <= nx-1) for (int k = i; k < nx; k++) l.pb(x[k]);
    if(j <= ny-1) for (int k = j; k < ny; k++) l.pb(y[k]);    
    return l;
}

ll mod(ll a, ll n, ll r){
    ll res=1;
    while(n>0){
        if(n&1) res = res * a % r;
        a = a * a % r;
        n >>= 1;
    }
    return res;
}

ll divide(const palivec &x, const palivec &y, ll r){
    palivec l;
    ll nx = x.size();
    ll ny = y.size();
    ll i=0, j=0;
    ll res = 1;
    while((j <= ny-1)){
        if(x[i].first == y[j].first) {
            if(x[i].second != y[j].second) res = res * mod(x[i].first, x[i].second - y[j].second, r) % r;
            i++;
            j++;
        }
        else if(x[i].first < y[j].first) {
            res = res * mod(x[i].first, x[i].second, r) % r; 
            i++;
        }
    }
    for (int k = i; k < nx; k++) res = res * mod(x[k].first, x[k].second, r) % r; 


    return res;
}


/*
ll mod(const palivec &x, ll y){
    ll s=1;
    FOR(x.size()){
        int e=x[i].second;
        ll xx = x[i].first;
        ll res=1;
        while(e>0){
            if(e&1) res = res * xx % y;
            xx = (xx * xx) % y;
            e >>= 1;
        }
        s *= res % y;
    }
    return s%y;
}
*/

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll r=1e9+7;
    cin >> n;
    lvec a(n);
    VIN(a);
    ll ma = 0;
    FOR(n){
        ma = max(a[i], ma);
    }
    palivec l;
    vector<palivec> p;
    lvec mf = mfactor((ll)ma+1);
    FOR(n){
        palivec plist = get_prime(a[i], mf);
        p.pb(plist);
        l = plcm(plist, l);
    }
    //ll modl = mod(l, r);
    ll ans=0;
    /*
    FOR(n){
        palivec d = divide(l, p[i]);
        ans += mod(d, r)%r;
    }
    */
    FOR(n) ans += divide(l, p[i], r);
    //FOR(n) ans += modl % a[i], r);

    cout << ans % r << endl;
}