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>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;

long long gcd(long long x, long long y) {
    long long g,l;
    g = max(x,y);
    l = min(x,y);
    long long a = g%l;
    return a==0? l : gcd(l,a);
}

long long MCM(vector<long long> &A, long long l, long long r){
    if(r-l ==1){
        return A[l]*A[r]/gcd(A[l],A[r]);
    }else{
        long long a = MCM(A, l, (r+l)/2);
        long long b = MCM(A, (r+l)/2 + 1, r);
        return a*b/gcd(a,b);
    }
}

int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> P1(1010, 0);
    vector<vector<long long>> P2(N, vector<long long>(1010, 0));
    
    for(long long i=0; i<N; i++){
        cin >> A[i];
        long long tmp = A[i];
        for(long long j=2; j<1001;j++){
            while(true){
                if(tmp % j == 0){
                    tmp /= j;
                    P2[i][j]++;
                    continue;
                }else{
                    break;
                }
            }
            P1[j] = max(P1[j], P2[i][j]);
        }

        //mcm = (mcm * A[i]) / (gcd(mcm,A[i]));
        //mcm *= A[i];
    }
    
    //mcm = MCM(A, 0, N-1);    
    long long mcm = 1;
    long long sum = 0;
    /*
    for(long long i=2;i<1001;i++){
        if(P1[i] != 0){
            mcm *= i*P1[i];
        }
    }*/
    for(long long i=0; i<N; i++){
        long long tmp = 1;
        for(long long j=2;j<1001;j++){
            if(P1[j] != 0 && P1[j] - P2[i][j] > 0){
                long long a = (long long)((pow(double(j), double(P1[j] - P2[i][j])))+0.5);
                //cout << "tmp11:" << (pow(double(j), double(P1[j] - P2[i][j]))) << endl;
                //cout << "aaaaa:" << a <<endl;
                //cout << "tmp00:"<< tmp << endl;
                tmp *= a;
                //cout << "tmp01:"<< tmp << endl;
                //cout << "tmp02:"<< a << endl;
                tmp %= mo;
            }     
        }
        //sum += ((mcm / A[i]) % mo);
        sum += tmp;
        sum %= mo;
    }


    /*rep(i,10){
        cout << A[i][i] <<' ';
    }
    cout << endl;
    */
    cout << sum << endl;
}