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: Wrong Answer)

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

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

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

    val n = sc.nextInt()

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

    val primes = mutableMapOf<Long, Int>()

    for (x in a) {
        var d = 2L
        var y = x
        while (d * d <= x) {
            var c = 0
            while (y % d == 0L) {
                c++
                y /= d
            }
            if (c!=0 && (!primes.containsKey(d) || primes[d]!! < c)) primes[d] = c
            d++
        }
        if (y == x && x != 1L) if (!primes.containsKey(x)) primes[x] = 1

    }

    var lcm = 1L
    for (p in primes) {
        lcm = mul(lcm, pow(p.key, p.value))
    }

    var sinv = 0L
    for (x in a) {
        sinv = (sinv + inv(x)) % mod
    }

    println(mul(lcm, sinv))
}

fun inv(a: Long): Long {
    return pow(a, (mod - 2).toInt())
}

fun pow(a: Long, x: Int): Long {
    var res = 1L
    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: Long, b: Long): Long {
    return ((a * b) % mod)
}

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()
}