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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}


ll pr[1000]={},pr2[10000],pma=0;
void makelcm(ll n){
    ll a=0;
    while(n%2==0){
        n/=2;
        a++;
    }
    pr[2]=max2(pr[2],a);
    repp(i,3,min2(n,999)+2,2){
        if(n<i) break;
        if(n%i==0){
            a=0;
            while(n%i==0){
                n/=i;
                a++;
            }
            pr[i]=max2(pr[i],a);
        }
    }
    if(n>1000){
        pr2[pma]=n;
        pma++;
    }
}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
/*aのn乗(mod)*/
ll modpow(ll a, ll n, ll mod){
    ll i,s[digits(n,2)],ans=1;
    for(i=0;i<digits(n,2);i++){
        s[i]= i==0 ? a : s[i-1]*s[i-1]%mod ;
        ans*=placenai(n,2,i+1)==1?s[i]:1; ans%=mod;}
    return n==0?1:ans;
}

ll inv[1000005];
void makeinv(ll n){
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        // finv[i] = finv[i - 1] * inv[i] % MOD1;
        }
}

int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    ll a[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
        makelcm(a[i]);
    }
    makeinv(maxn(n,a));
    ll lcms=1;
    rep(i,0,1000){
        if(pr[i]!=0){
            lcms = lcms*modpow(i,pr[i],MOD1)%MOD1;
        }
    }
    rep(i,0,pma){
        lcms = lcms*pr2[i]%MOD1;
    }
    // printf("%lld\n",lcms);
    ll b[n];
    rep(i,0,n){
        b[i]=lcms*inv[a[i]];
        b[i]%=MOD1;
        // printf("%lld ",b[i]);
    }
    rep(i,0,n){
        ans+=b[i];
        ans%=MOD1;
    }
    // rep(i,0,100){
    //     printf("%lld ",pr[i]);
    // }
    printf("%lld\n",ans);
    return 0;
}