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: Accepted)

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

#define MOD 1000000007
#define MAX 1000005
long long int fac[MAX], finv[MAX], inv[MAX];
void MOD_COM_init(){
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for(int i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long int MOD_pow(long long int a, long long int n){
    long long int res = 1;
    while(n>0){
        if(n&1){
            res = res*a % MOD;
        }
        a = a*a % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    scanf("%d", &n);
    lld a[n];
    rep(i, 0, n){
        scanf("%lld", &a[i]);
    }
    MOD_COM_init();
    lld t[1000001] = {0};
    rep(i, 0, n){
        lld cnt, buf;
        buf = a[i];
        cnt = 0;
        while(buf % 2 == 0){
            buf /= 2;
            cnt++;
        }
        if(cnt > t[2]){
            t[2] = cnt;
        }
        for(int j=3; j*j<=buf; j+=2){
            cnt = 0;
            while(buf % j == 0){
                cnt++;
                buf /= j;
            }
            if(cnt > t[j]){
                t[j] = cnt;
            }
        }
        if(buf > 1){
            if(t[buf] == 0){
                t[buf] = 1;
            }
        }
    }
    lld x = 1;
    rep(i, 0, 1000001){
        if(t[i] != 0){
            x *= MOD_pow((lld)i, t[i]);
            x %= MOD;
        }
    }
    lld ans = 0;
    rep(i, 0, n){
        ans += x * inv[a[i]] % MOD;
        ans %= MOD;
    }
    printf("%lld", ans);

    return 0;
}