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 Kotlin (1.0.0) (judge verdict: Time Limit Exceeded)

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

val mod = (1e9 + 7).toInt()

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()

    val a = Array(n) { sc.nextInt() }

    val primes = mutableMapOf<Int, Int>()

    val maxN = 10e6.toInt()
    val divs = Array((maxN + 1)) { 1 }

    var d = 1
    while (d * d <= maxN) {
        d += 1
        if (divs[d] != 1) continue

        var i = d
        while (i <= maxN) {
            divs[i] = d
            i += d
        }
    }

    for (x in a) {
        var y = x

        while (y > 1) {
            val p = divs[y]
            var c = 0
            while (divs[y] == p) {
                c += 1
                y /= divs[y]
            }

            if (!primes.containsKey(p) || primes[p]!! < c) primes[p] = c
        }
    }

    var lcm = 1
    for (p in primes.keys) {
        lcm = mul(lcm, pow(p, primes[p]!!))
    }

    var res = 0
    for (x in a) {
        res = (res + mul(lcm, inv(x))) % mod
    }

    println(res)
}

fun inv(a: Int): Int {
    return pow(a, mod - 2)
}

fun pow(a: Int, x: Int): Int {
    var res = 1
    var m = a
    var x = x
    while (x > 0) {
        if (x % 2 == 1) res = mul(res, m)
        m = mul(m, m)
        x /= 2
    }
    return res
}

fun mul(a: Int, b: Int): Int {
    return ((a.toLong() * b) % mod).toInt()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}