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++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
int64_t pow(int64_t x, T n, int64_t mod = std::numeric_limits<int64_t>::max()) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<__int128>(res) * static_cast<__int128>(x) % mod;
    x = static_cast<__int128>(x) * static_cast<__int128>(x) % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a;
    u -= t * v;
    std::swap(a, m);
    std::swap(u, v);
  }
  assert(m == 1);
  return u;
}

class Prime {
 public:
  template <typename T>
  static bool is_prime(T n) {
    if (n == 0 || n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (T i = 3; i * i < n + 1; i += 2) {
      if (n % i == 0) return false;
    }
    return true;
  }

  template <typename T>
  static std::vector<T> factor(T n) {
    std::vector<T> res;
    for (T i = 2; i * i < n + 1; i++) {
      while (n % i == 0) {
        n /= i;
        res.emplace_back(i);
      }
    }
    if (n != 1) res.emplace_back(n);
    return res;
  }

  template <typename T>
  static T totient(T n) {
    T res = 1;
    std::vector<T> primes = factor(n);
    std::map<T, int> mp;
    for (T p : primes) {
      mp[p]++;
    }
    for (const auto &[p, c] : mp) {
      res *= pow(p, c - 1) * (p - 1);
    }
    return res;
  }

  template <typename T>
  static std::vector<T> sieve_of_eratosthenes(T n) {
    std::vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (T i = 2; i * i < n + 1; i++) {
      if (!is_prime[i]) continue;
      for (T k = 2 * i; k < n + 1; k += i) {
        is_prime[k] = false;
      }
    }
    std::vector<T> res;
    for (T i = 0; i < n + 1; i++) {
      if (is_prime[i]) res.emplace_back(i);
    }
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  map<int64_t, int64_t> primes;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    auto prime = Prime::factor(A[i]);
    map<int64_t, int64_t> mp;
    for (auto p : prime) {
      mp[p]++;
    }
    for (auto [k, v] : mp) {
      primes[k] = max(primes[k], v);
    }
  }
  int64_t l = 1;
  for (auto [k, v] : primes) {
    l *= pow(k, v, static_cast<int64_t>(MOD));
    l %= MOD;
  }
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    res += (l * inverse(A[i], static_cast<int64_t>(MOD)) % MOD);
    res %= MOD;
  }
  cout << res << '\n';
  return 0;
}