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>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

namespace mp = boost::multiprecision;
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const mp::cpp_int mod = 1000000007;

mp::cpp_int gcd_impl( mp::cpp_int n, mp::cpp_int m ) {
        for( int i = 0; i < 10; ++i ) {
                mp::cpp_int t = n - m;
                bool q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

mp::cpp_int gcd( mp::cpp_int n, mp::cpp_int m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

mp::cpp_int lcm(mp::cpp_int a, mp::cpp_int b) {
    return a * b / gcd(a, b);
}

mp::cpp_int AB(mp::cpp_int a, mp::cpp_int b) {
    mp::cpp_int left = 1, right = b;
    mp::cpp_int temp = (left + right) / 2;
    while (left != right) {
        temp = (left + right) / 2;
        if (temp * a < b) left = temp;
        else if (temp * a > b) right = temp;
        if (temp * a == b) break;
    }
    return temp;
}

signed main() {
    mp::cpp_int N;
    cin >> N;
    vector<mp::cpp_int> A;
    for (int i = 0; i < N; i++) {
        mp::cpp_int temp;
        cin >> temp;
        A.push_back(temp);
    }
    mp::cpp_int temp = *A.begin();
    mp::cpp_int ans = 1;
    for (auto itr = A.begin() + 1; itr < A.end(); itr++) {
        mp::cpp_int before = temp;
        temp = boost::math::lcm(temp, *itr);
        ans *= (temp / before);
        ans += AB(*itr, temp);
        ans %= mod;
    }
    cout << ans << endl;
}