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>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    int MAXN = 1e6 + 10;
    vector<int> cnt(MAXN, 0);
    vector<int> res(MAXN, 1);
    for (int i = 2;i < MAXN;i++) {
        if (res[i] == 1) {
            for (int j = i;j < MAXN;j += i) {
                res[j] = i;
            }
        }
    }

    for (auto x : a) {
        int g = x;
        unordered_map<int,int> m;
        while (g != 1) {
            m[res[g]]++;
            g /= res[g];
        }
        for (auto y : m) {
            chkmax(cnt[y.X], y.Y);
        }
    }


    int ans = 0;

    int f = 1;

    for (int i = 0;i < MAXN;i++) {
        for (int j = 0;j < cnt[i];j++) {
            (f *= i) %= mod;
        }
    }

    for (auto x : a) {
        int g = x;
        unordered_map<int,int> m;
        int cur = f;
        while (g != 1) {
            (cur *= ppow(res[g], mod - 2)) %= mod;
            g /= res[g];
        }
        (ans += cur) %= mod;
    }

    cout << ans;

    return 0;
}