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

package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Inv(n int) int {
  if n <= 1 { return 1 }
  return p - Inv(p % n) * (p / n) % p
}

const p = 998244353

func Solve() {
  var N int
  var A []int
  NextInt(&N)
  NextIntVec(&A)
  V := MaxInt(A...)
  D := make([][]int, V + 1)
  M := make([][]int, V + 1)
  for i := range D {
    D[i] = make([]int, 0)
    M[i] = []int{i}
  }
  for d := 1; d <= V; d++ {
    for k := 2; k * d <= V; k++ {
      D[k * d] = append(D[k * d], d)
      M[d] = append(M[d], k * d)
    }
  }
  W := make([]int, V + 1)
  for w := 1; w <= V; w++ {
    W[w] = Inv(w)
    for _, d := range D[w] {
      W[w] -= W[d]
      if W[w] < 0 { W[w] += p }
    }
  }
  C := make([]int, V + 1)
  for _, a := range A { C[a]++ }
  S := 0
  H := Inv(2)
  var c, s int
  for d := 1; d <= V; d++ {
    c, s = 0, 0
    for _, m := range M[d] {
      if C[m] == 0 { continue }
      c += m * C[m]
      s = (s + m * m * C[m] % p) % p
    }
    if c == 0 { continue }
    c %= p
    S = (S + W[d] * ((c * c - s + p) % p * H % p) % p) % p
  }
  Write(S)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}