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;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll n;
vector<ll> vec1(10000),vec2(10000);
ll calc(ll k){
  ll t1 = k;
  ll ans = 1;
  while(1){
    bool can = false;
    rep(i,n){
      if(vec1[i] % t1 == 0){
        vec1[i] /= t1;
        can = true;
      }
    }
    if(can){
      ans *= k;
    }else{
      break;
    }
  }
  //cout << k << " " << ans << endl;
  return ans;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

ll MAX = 1000000;
int main(){
  cin >> n;
  vec1.resize(n);
  rep(i,n){
    cin >> vec1[i];
    vec2[i] = vec1[i];
  }
  vector<ll> vec(1000000,0);
  vec[0] = 1;
  ll sq = (ll)sqrt(2000000);
  vector<ll> sosu,sosucou;
  REP(i,2,sq){
    ll t1 = 2 * i;
    while(t1 <= 1000000){
      vec[t1-1] = 1;
      t1 += i;
    }
  }
  rep(i,sq){
    if(vec[i] == 0){
      sosu.push_back(i+1);
    }
  }
  ll len = sosu.size();

  ll gca = 1;
  ll ans = 0;
  rep(i,len){
    //cout << sosu[i] << " ";
    gca *= calc(sosu[i]);
    gca %= mod;
  }
  sort(all(vec1));
  //cout << gca << endl;
  rep(i,n){
    if(i == 0 || vec1[i] != vec1[i-1]){
      gca *= vec1[i];
      gca %= mod;
    }
  }
  //cout << gca << endl;

  //cout << gca << endl;
  rep(i,n){
    ans += gca * modinv(vec2[i],mod);
    ans %= mod;
  }
  cout << ans << endl;
}