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>

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M> class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept
      : a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
// }}}
// {{{ Decompose Prime
std::map<ll, ll> decomposePrime(ll n) {
  std::map<ll, ll> m;
  ll x = 2;
  while (x * x <= n) {
    if (n % x == 0) {
      m[x]++;
      n /= x;
    } else {
      x++;
    }
  }
  if (n > 1)
    m[n]++;
  return m;
}
// }}}

ll mpow(ll x, ll y, ll m) {
  if (y == 0)
    return 1;
  else if (y % 2 == 1)
    return x * mpow(x, y - 1, m) % m;
  else
    return mpow(x * x % m, y / 2, m) % m;
}

const ll M = 1000000007;
using mint = modint<1000000007>;

signed main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  vector<map<ll, ll>> mm(N);
  map<ll, ll> mp; // {prime -> # of the prime}
  rep(i, N) { cin >> a[i]; }
  rep(i, N) {
    auto m = decomposePrime(a[i]);
    for (auto e : m) {
      chmax(mp[e.first], e.second);
    }
    mm[i] = m;
  }
  // printf("sum: ");
  // for (auto e : mp) {
  //  printf("%d^%d x ", e.first, e.second);
  //}
  // printf("1\n");

  mint ans(0);
  rep(i, N) {
    mint t(1);
    auto m = mm[i];
    // printf("%d: ", a[i]);
    for (auto e : mp) {
      // printf("%d^%d x ", e.first, e.second - m[e.first]);
      t *= mint(mpow(e.first, e.second - m[e.first], M));
    }
    // printf(" 1= %d\n", t.value());
    ans += t;
  }
  cout << ans.value() << endl;
  return 0;
}