Problem:
Score : 700 points

Problem Statement

We have an integer sequence of length N: A_0,A_1,\cdots,A_{N-1}.

Find the following sum (\mathrm{lcm}(a, b) denotes the least common multiple of a and b):

\sum_{i=0}^{N-2} \sum_{j=i+1}^{N-1} \mathrm{lcm}(A_i,A_j)

Since the answer may be enormous, compute it modulo 998244353.

Constraints

1 \leq N \leq 200000

1 \leq A_i \leq 1000000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_0\ A_1\ \cdots\ A_{N-1}

Output

Print the sum modulo 998244353.

Sample Input 1

3
2 4 6

Sample Output 1

22

\mathrm{lcm}(2,4)+\mathrm{lcm}(2,6)+\mathrm{lcm}(4,6)=4+6+12=22.

Sample Input 2

8
1 2 3 4 6 8 12 12

Sample Output 2

313

Sample Input 3

10
356822 296174 484500 710640 518322 888250 259161 609120 592348 713644

Sample Output 3

353891724

Solution in Kotlin (1.0.0) (judge verdict: Time Limit Exceeded)

fun main(args: Array<String>) {
    val MOD = 998244353L
    val N = nextInt()
    val A = listOfLong()
    var ans = 0L
    for (i in 0 until N-1) {
        val a = prime(A[i])
        for (j in i+1 until N) {
            val b = prime(A[j])
            val l = lcm(a, b)
//System.err.println("a:${A[i]} b:${A[j]} lcm:${l}")
            ans += l
            ans %= MOD
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun prime(v: Long): List<Pair<Long, Long>> {
    var a = v.toDouble()
    var r = mutableListOf<Pair<Long, Long>>()
    var j = 2.0
    while (j <= Math.floor(v.toDouble() / 2) && 1 < a) {
        var i = 0.0
        while (a % j == 0.0) {
            a = Math.floor(a / j)
            i++
        }
        if (i > 0) r.add(Pair(j.toLong(), i.toLong()))
        j += 1 + (j.toLong() and 1L)
    }
    if (r.size == 0) r.add(Pair(v.toLong(), 1L))
    return r.toList()
}
fun lcm(a: List<Pair<Long, Long>>, b: List<Pair<Long, Long>>): Long {
    val r = mutableListOf<Pair<Long, Long>>()
    var na = 0
    var nb = 0
    while (na < a.size && nb < b.size) {
        if (a[na].first == b[nb].first) {
            r.add(Pair(a[na].first, Math.max(a[na].second, b[nb].second)))
            na++
            nb++
        } else if (a[na].first < b[nb].first) {
            r.add(Pair(a[na].first, a[na].second))
            na++
        } else if (a[na].first > b[nb].first) {
            r.add(Pair(b[nb].first, b[nb].second))
            nb++
        }
    }
    while (na < a.size) {
        r.add(Pair(a[na].first, a[na].second))
        na++
    }
    while (nb < b.size) {
        r.add(Pair(b[nb].first, b[nb].second))
        nb++
    }
    var ans = 1L
    r.forEach {
        ans *= Math.pow(it.first.toDouble(), it.second.toDouble()).toLong()
    }
    return ans
}