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 <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
ll a[11000];

map<ll, int> prime_factor(ll n) {
   map<ll, int> ret;
   for(ll i = 2; i * i <= n; i++) {
     while(n % i == 0) {
       ret[i]++;
       n /= i;
     }
   }
   if(n != 1) ret[n] = 1;
   return ret;
 }

bool is_prime[ 1100000 ];
vector<int> prime;
void Eratosthenes( const int N )
{
  for( int i = 0; i <= N; i++ )
  {
    is_prime[ i ] = true;//初期化
  }    
  for( int i = 2; i <= N; i++ )
  {
      if( is_prime[ i ] )
      {
          for( int j = 2 * i; j <= N; j += i )
          {
              is_prime[ j ] = false;
          }
      }
  }
}

ll data[1100000];
ll beki[1100000][21];

int main () {
  cin >> N;
  rep(i, N) cin >> a[i];

  map<ll, int> mps[11000];

  rep(i, N) {
    mps[i] = prime_factor(a[i]);
  }

  map<ll, int> all;
  rep(k, N) {
   for(ll i = 2; i * i <= a[k]; i++) {
     while(a[k] % i == 0) {
       all[i]++;
       a[k] /= i;
     }
   }
   if(a[k] != 1) all[a[k]] = 1;
  }

  Eratosthenes(1100000);
  vector<int> primes;
  for (int k=2;k<=1000000;++k) {
    if(is_prime[k]) primes.push_back(k);
  }

  vector<int> primes2;
  for (auto p: primes) {
    if (all[p] != 0) primes2.push_back(p);
  }

  //printv(primes2);

  for (auto p: primes2) {
    int tmp = 0;
    rep(i, N) {
      chmax(tmp, mps[i][p]);
    }

    data[p] = tmp;
  }

  ll ans = 0LL;

  for (auto p: primes2) {
    ll tmp = 1LL;
    beki[p][0] = 1LL;
    rep(i, 20) {
      tmp *= p;
      tmp %= MOD;
      beki[p][i] = tmp;
      //cout << p << " " << i << " " << tmp << "\n";
    }
  }

  //printv(primes2);

  rep(i, N) {
    ll tmp = 1LL;

    for (auto p: primes2) {
      tmp *= beki[p][data[p] - mps[i][p]];
      //cout << p << data[p] - mps[i][p] << "\n";
      tmp %= MOD;
    }

    ans += tmp;
    ans %= MOD;
  }

  cout << ans << "\n";
}