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)

#include <bits/stdc++.h>

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

#define mp make_pair

constexpr int64_t M = 1e9 + 7;

int64_t modpow(int64_t n, int64_t m) {
    if (m == 0) return 1;
    else if (m % 2 == 0) {
        int64_t r = modpow(n, m / 2);
        return (r * r) % M;
    } else {
        int64_t r = modpow(n, m / 2);
        return ((n * r) % M * r) % M;
    }
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    int N;
    cin >> N;
    vector<int> as;
    for (int i = 0; i < N; ++i) {
        int ai;
        cin >> ai;
        as.push_back(ai);
    }
    vector<bool> is_prime(1001, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= is_prime.size(); ++i) {
        if (is_prime[i]) {
            for (int j = i + i; j < is_prime.size(); j += i) {
                is_prime[j] = false;
            }
        }
    }
    vector<int> ps;
    for (int i = 0; i < is_prime.size(); ++i) {
        if (is_prime[i]) ps.push_back(i);
    }
    vector<int> prime_vec_max(1000001, 0);
    for (int i = 0; i < N; ++i) {
        int ai = as[i];
        vector<pair<int, int>> primes;
        while (ai != 1) {
            bool cont = false;
            for (const auto& p : ps) {
                if (ai % p == 0) {
                    if (primes.size() == 0 || primes.back().first != p) {
                        primes.push_back(make_pair(p, 1));
                    } else {
                        primes.back().second++;
                    }
                    ai /= p;
                    cont = true;
                    break;
                }
            }
            if (!cont) {
                if (primes.size() == 0 || primes.back().first != ai) {
                    primes.push_back(make_pair(ai, 1));
                } else {
                    primes.back().second++;
                }
                break;
            }
        }
        for (const auto kv : primes) {
            prime_vec_max[kv.first] = max(prime_vec_max[kv.first], kv.second);
        }
    }
    int64_t p = 1;
    for (int i = 0; i < prime_vec_max.size(); ++i) {
        if (i != 0) {
            p = (p * modpow(i, prime_vec_max[i])) % M;
        }
    }
    int64_t res = 0;
    for (const auto a : as) {
        res = res + modinv(a, M) % M;
    }
    cout << (p * res) % M << endl;
}