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: Time Limit Exceeded)

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef unordered_map<ULL, ULL> UM;
ULL MOD=1e9+7;
UM cnvt(ULL n){
UM Z;
if(n<=1){ Z[n]=1; return Z; }
while(n%2==0){ n/=2; Z[2]++; }
for(ULL i=3; i*i<=n; i+=2){ while(n%i==0){ n/=i; Z[i]++; } }
if(n!=1){ Z[n]=1; }
return Z;
}
UM lcm(UM X, UM Y){
for(auto i:Y){ X[i.first]=max(X[i.first], i.second); }
return X;
}
ULL pw(ULL a, ULL n){ ULL b=1; while(n){ if(n&1){ b=(b*a)%MOD; } a=(a*a)%MOD; n>>=1; } return b; }
ULL recv(UM X){
ULL z=1;
for(auto i:X){ z=(z*pw(i.first, i.second))%MOD; }
return z;
}
ULL waru(ULL a, ULL b){ return (a*pw(b, MOD-2))%MOD; }

int main(){
ULL M, N, i, ans=0; UM L; cin >> N; ULL A[N];
cin >> A[0]; L=cnvt(A[0]);
for(i=1; i<N; i++){ cin >> A[i]; L=lcm(L, cnvt(A[i])); }
M=recv(L);
for(i=0; i<N; i++){ ans=(ans+waru(M, A[i]))%MOD; }
cout << ans << "\n";
}