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 ;
#define ll long long
#define ff first
#define ss second
const ll mod = 1e9 + 7 ;
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
///////////////////////////////////////////////////////////
const int nmax = 1e6 + 4 ;
vector < int > p(nmax) ;
ll power ( ll x , ll n){
    if(n==0) return 1 ;
    if(n==1) return x ;
    ll y = power(x,n/2);
    if(n%2==0) return multiply(y,y) ;
    return multiply(x,multiply(y,y));
}
//////////////////////////////////////////////////////////
void solve( ){
    /// b[i]=LCM/a[i]
    /// summation of b[i]%mod
    for( int i = 0 ; i < nmax ; i++) p[i] = i ;
    for( int i = 2 ; i < nmax ; i++){
        if(p[i]==i){
            for( int j = i;  j < nmax ; j+=i){
                p[j] = i ;
            }
        }
    }
    int n ; cin >> n ;
    vector < int > a(n) ;
    for( int i = 0 ; i < n; i++) cin >> a[i] ;
    ll lcm = 1 ;
    vector < int > pp(nmax) ;
    for( int i = 0 ; i < n;i++){
        int x = a[i] ;
        while(x!=1){
            int y = p[x];
            int cnt = 0 ;
            while(x%y==0){
                cnt++;
                x/=y;
            }
            //cout << "( " <<  y << " " << cnt << ") " ;
            pp[y] = max(pp[y],cnt);
        }
        //cout << "\n";
    }
    for( int i = 2 ; i < nmax ; i++){
        if(pp[i]!=0)
            lcm = multiply(lcm,power(i,pp[i]));
    }
    //lcm = 499998500001000000 ;
    //cout << lcm << "\n" ;
    ll ans  = 0 ;
    //cout << power(2,10) << " " ;
    for( int i = 0 ; i < n; i++){
        ans = add(ans,multiply(lcm,power(a[i],mod-2)));
        //ans = add(ans,lcm/a[i]);
    }
    cout << ans << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test_case=1 ;
    //cin >> test_case ;
    for( int i = 1 ; i <= test_case ; i++){
        solve( );
    }
}