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>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

/*MOD int=============================*/
template<std::int_fast64_t Mod>
class modint {
    using i64 = std::int_fast64_t;
public:
    i64 val;
    //constructor
    constexpr modint(const i64 p=0) noexcept : val(p>=0 ? p%Mod : (Mod+(p%Mod))%Mod) {}

    //std::cin, std::cout
    friend std::ostream &operator<<(std::ostream &os, const modint &x) {
        return os << x.val;
    }
    friend std::istream &operator>>(std::istream &is, modint &x) {
        is >> x.val;
        x.val %= Mod;
        if(x.val < 0) x.val += Mod;  // <- 負数対応
        return is;
    }

    //operator
    constexpr modint operator+(const modint b) const noexcept { return modint(*this) += b; }

    constexpr modint operator-(const modint b) const noexcept { return modint(*this) -= b; }

    constexpr modint operator*(const modint b) const noexcept { return modint(*this) *= b; }

    constexpr modint operator/(const modint b) const noexcept { return modint(*this) /= b; }

    constexpr modint operator-() const noexcept { return modint() - *this; }

    constexpr bool operator==(const modint &b) const noexcept { return this->val == b.val; }

    constexpr bool operator!=(const modint &b) const noexcept { return this->val != b.val; }

    constexpr modint &operator=(const modint b) noexcept {
        val = b.val;
        return *this;
    }
    constexpr modint &operator=(const i64 b) noexcept {
        val = modint<Mod>(b).val;
        return *this;
    }
    constexpr modint &operator+=(const modint b) noexcept {
        if((val += b.val) >= Mod) val -= Mod;
        return *this;
    }
    constexpr modint &operator-=(const modint b) noexcept {
        if(val < b.val) val += Mod;
        val -= b.val;
        return *this;
    }
    constexpr modint &operator*=(const modint b) noexcept {
        val = val * b.val % Mod;
        return *this;
    }
    constexpr modint &operator/=(modint b) noexcept {
        val *= b.inverse().val;
        val %= Mod;
        return *this;
    }
    constexpr modint inverse() noexcept {
        i64 m=Mod, u=1, v=0, t=1;
        while(m) {
            t = val/m;
            val -= t*m; std::swap(val,m);
            u -= t*v; std::swap(u,v);
        }
        return modint(u);
    }
    // calc val^n
    constexpr  modint pow(i64 n) noexcept {
        modint res = 1, a = val;
        while(n > 0) {
            if(n & 1) res = res * a;
            a = a * a;
            n >>= 1;
        }
        return res;
    }
};
using mint = modint<mod>;

/*FUNCs=================================================*/
class largeLCM {
private:
    std::map<int, int> val;
public:
    explicit largeLCM(int n=1) {calc(n);};
    void calc(int_fast32_t x) noexcept {
        int tmp, X = x;
        for(int i = 2; i*i <= x; ++i) {
            tmp = 0;
            while(X%i == 0) {
                ++tmp;
                X /= i;
            }
            if(0 < tmp) val[i] = std::max(val[i], tmp);
        }
        if(X != 1) val[X] = 1;
    }
    modint<mod> convert() const noexcept {
        modint<mod> ret = 1;
        for(auto p : val) {
//            debug(p.first);debug(p.second);
            if(p.second) ret *= modint<mod>(p.first).pow(p.second);
        }
        return ret;
    }
};

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    int n; cin >> n;
    mint answer = 0, tmp;
    vec<int> a(n); rep(i,n) cin >> a[i];

    largeLCM LCM(a[0]);
    rep1(i,n-2) LCM.calc(a[i]);
    const mint lcm_mod = LCM.convert();
//    debug(lcm_mod);

    rep(i,n) {
        tmp = a[i];
        tmp = lcm_mod/tmp;
        answer += tmp;
//        debug(tmp);
//        debug(lcm_mod/tmp);
//        debug(answer);
    }
    cout << answer << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}