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;
const int mod=1e9+7;
const int mex=1000001;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 
ll int power(ll int a,int b)
{
    ll int ans=1,f=a;
    while(b)
    {
        if(b&1) ans=(ans*f)%mod;
        f=(f*f)%mod;
        b=b>>1;
    }
    return ans%mod;
}
int main()
{
    fast
  int n;
  cin>>n;
 ll int arr[n];
 vector<pair<int,int> > v[n+1];
 fo(j,0,n)
 {cin>>arr[j];
 int tp=arr[j];
 for(ll int i=2;i*i<=arr[j];i++)
 {
     int cnt=0;
     while(tp%i==0)
     {
         tp=tp/i;
         cnt++;
     }
     if(cnt) v[j].pb({i,cnt});
 }
 if(tp!=1) v[j].pb({tp,1});
 }
int mp[mex]={0},ans1[n+1];
fo(i,0,n+1)
ans1[i]=1;
 fo(i,0,n)
 {
    // cout<<'#'<<i<<" ";
     fo(j,0,sz(v[i]))
     {
        // cout<<v[i][j].fi<<" "<<v[i][j].se<<"  ";
         ans1[i]=(ans1[i]*power(v[i][j].fi,v[i][j].se))%mod;
         mp[v[i][j].fi]=max(mp[v[i][j].fi],v[i][j].se);
     }
     //cout<<endl;
 }
 ll int ans=1;
 vector<pair<int,int> > v2;
 fo(i,0,mex)
 {
     if(mp[i])
     {v2.pb({i,mp[i]});
     ans=(ans*power(i,mp[i]))%mod;
     //cout<<i<<" "<<mp[i]<<"  ";
     }
     
 }
 ans%=mod;
 ll int sum=0;
 fo(i,0,n)
 {
    // cout<<arr[i]<<" ";
    ll int an=(ans*power(arr[i],mod-2))%mod;
    sum+=an;
   // cout<<an<<" ";
    sum%=mod;
 }
 cout<<sum;
}