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

import java.util.*

fun main(omkar: Array<String>) {
    val n = readLine()!!.toInt()
    val tokenizer = StringTokenizer(readLine()!!)
    val array = IntArray(n) { tokenizer.nextToken().toInt() }
    val primes = Array(1000001) { mutableListOf<Int>() }
    for (p in 2..1000000) {
        if (primes[p].isEmpty()) {
            var k = p
            while (k <= 1000000) {
                primes[k].add(p)
                k += p
            }
        }
    }
    val sums = LongArray(1000001)
    for (k in array) {
        val kl = k.toLong()
        fun recur(d: Int) {
            if (primes[k].isEmpty()) {
                sums[d] += kl
            } else {
                val p = primes[k].removeAt(primes[k].size - 1)
                var dn = d
                recur(dn)
                while ((k / dn) % p == 0) {
                    dn *= p
                    recur(dn)
                }
                primes[k].add(p)
            }
        }
        recur(1)
    }
    val reciprocal = LongArray(1000001)
    reciprocal[1] = 1L
    val dp = LongArray(1000001)
    dp[1] = 1L
    for (k in 2..1000000) {
        val p = primes[k][0]
        if (k == p) {
            reciprocal[k] = k.toLong() pow -1
        } else {
            reciprocal[k] = (reciprocal[p] * reciprocal[k / p]) % MOD
        }
        if (primes[k].size == 1) {
            dp[k] = reciprocal[k] - reciprocal[k / primes[k][0]]
        } else {
            var power = 1
            while ((k / power) % p == 0) {
                power *= p
            }
            dp[k] = dp[power] * dp[k / power]
            dp[k] %= MOD
        }
        sums[k] *= dp[k]
        sums[k] %= MOD
    }
    var answer = 0L
    for (k in array) {
        val kl = k.toLong()
        answer -= kl
        fun recur(d: Int) {
            if (primes[k].isEmpty()) {
                answer += kl * sums[d]
            } else {
                val p = primes[k].removeAt(primes[k].size - 1)
                var dn = d
                recur(dn)
                while ((k / dn) % p == 0) {
                    dn *= p
                    recur(dn)
                }
                primes[k].add(p)
            }
        }
        recur(1)
        answer %= MOD
    }
    answer *= reciprocal[2]
    answer %= MOD
    answer += MOD
    answer %= MOD
    println(answer)
}

val MOD: Long = 998244353
val MOD_TOTIENT = (MOD - 1).toInt()

infix fun Long.pow(power: Int): Long {
    var e = power
    e %= MOD_TOTIENT
    if (e < 0) {
        e += MOD_TOTIENT
    }
    if (e == 0 && this == 0L) {
        return this
    }
    var b = this
    var res = 1L
    while (e > 0) {
        if (e and 1 != 0) {
            res *= b
            res %= MOD
        }
        b *= b
        b %= MOD
        e = e shr 1
    }
    return res
}