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 C (Clang 3.8.0) (judge verdict: Accepted)

#include <stdio.h>

#define N 1000000
const int mod = 998244353;

int n;
int A[N+1];
int M[N+1];
int S[N+1];
int inv[N+1];

/*
\sum_{i<j} lcm(Ai,Aj)
\sum_{i<j} Ai Aj / gcd(Ai,Aj)
\sum_{d} 1/d \sum_{i<j: gcd(Ai, Aj) = d} Ai Aj

f(d) = \sum_{i,j: gcd(Ai, Aj) = d} Ai Aj
F(d) = \sum_{i,j: d | gcd(Ai, Aj)} Ai Aj
F(d) = \sum_{i,j: d | Ai, d | Aj)} Ai Aj
F(d) = (\sum_{i: d | Ai} Ai)^2
\sum_{d} 1/d \sum_{n: d|n} m(n/d) F(n)
\sum_{n} F(n) \sum_{d: d|n} 1/d m(n/d)
*/

int main(){
  int i, j, r, s;
  scanf("%d", &n);
  s = 0;
  for(i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    A[x]++;
    s += x;
    if(s >= mod) s -= mod;
  }
  inv[1] = 1;
  for(i=2;i<=N;i++) inv[i] = (long long) (mod - mod/i) * inv[mod%i] % mod;

  for(i=1;i<=N;i++){
    A[i] = (long long) i * A[i] % mod;
    for(j=2*i;j<=N;j+=i){
      A[i] = (A[i] + (long long) j * A[j]) % mod;
    }
  }

  for(i=1;i<=N;i++){
    A[i] = ((long long) A[i] * A[i]) % mod;
  }

  r = mod-s;
  for(i=N;i;i--){
    for(j=2*i;j<=N;j+=i){
      A[i] -= A[j];
      if(A[i] < 0) A[i] += mod;
    }
    r = (r + (long long) inv[i] * A[i]) % mod;
  }

  printf("%d\n", r&1?(r+mod)/2:r/2);

  return 0;
}