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 Ruby (2.7.1) (judge verdict: Accepted)

# frozen_string_literal: true

require 'prime'

module Residue
  MODULO = 1_000_000_007
  def self.inv(x)
    extgcd(x, MODULO)[0] % MODULO
  end

  def self.pow(x, i)
    retun 1 if i == 0
    r = 1
    i %= (MODULO - 1)
    while i > 0
      r = (r * x) % MODULO if (i & 1) != 0
      x = (x * x) % MODULO
      i >>= 1
    end
    r
  end

  def self.extgcd(a, b)
    x_2 = 1
    x_1 = 0
    y_2 = 0
    y_1 = 1
    r_2 = a
    r_1 = b
    loop do
      q, r = r_2.divmod(r_1)
      x = x_2 - q * x_1
      y = y_2 - q * y_1
      break if r == 0

      x_2 = x_1
      x_1 = x
      y_2 = y_1
      y_1 = y
      r_2 = r_1
      r_1 = r
    end
    [x_1, y_1, r_1]
  end
end


primes = Prime.each(1_000_000).to_a
n = gets.to_i
an = gets.split(' ').map(&:to_i)
pn = an.map { |ai| Prime.prime_division(ai) }
lcm_div = primes.zip(Array.new(primes.size, 0)).to_h
pn.each do |hi|
  hi.each do |arr|
    k, v = arr
    lcm_div[k] = v if lcm_div[k] < v
  end
end
lcm_div.reject! { |_k, v| v == 0 }
lcm_prod=1
lcm_div.each do |k, v|
  lcm_prod=(lcm_prod * Residue.pow(k, v)) % Residue::MODULO
end
res=an.sum do |ai|
  (lcm_prod * Residue.inv(ai))
end % Residue::MODULO
p res