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 (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>

int prime[1000] = {}, coeff[1000001] = {};
long long sum[1000001] = {};

int factorize(int n, int p[], int m[])
{
	int i, k;
	for (i = 0, k = 0; prime[i] * prime[i] <= n; i++) {
		if (n % prime[i] != 0) continue;
		p[k] = prime[i];
		for (m[k] = 0; n % p[k] == 0; m[k]++, n /= p[k]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, N, A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int j, k;
	for (i = 2, k = 0; i <= 1010; i++) {
		for (j = 0; j < k; j++) if (i % prime[j] == 0) break;
		if (j == k) prime[k++] = i;
	}
	
	int h, l[100], m[100], p[100], n[2], q, appear[1000001] = {};
	for (i = 1, q = 0; i <= N; i++) {
		sum[0] += A[i];
		k = factorize(A[i], p, m);
		for (j = 1, l[0] = 1; j <= k; j++) l[j] = 0;
		n[0] = p[0];
		n[1] = 1 - p[0];
		while (l[k] == 0) {
			if (coeff[n[0]] == 0) {
				coeff[n[0]] = n[1];
				appear[q++] = n[0];
			}
			sum[n[0]] += A[i] / n[0];
			
			for (j = 0; j < k && l[j] == m[j]; j++);
			if (j < k) {
				n[0] *= p[j];
				if (l[j] == 0) n[1] *= 1 - p[j];
			}
			for (l[j--]++; j >= 0; l[j--] = 0) {
				for (h = 0; h < l[j]; h++) n[0] /= p[j];
				if (l[j] > 0) n[1] /= 1 - p[j];
			}
		}
	}
	
	long long ans = (sum[0] % 998244353) * ((sum[0] - 1) % 998244353) % 998244353;
	for (j = 0; j < q; j++) {
		i = appear[j];
		sum[i] %= 998244353;
		ans = (ans + ((sum[i] * sum[i] % 998244353) * i % 998244353) * coeff[i] % 998244353) % 998244353;
	}
	
	ans = (ans + 998244353) % 998244353;
	printf("%lld\n", div_mod(ans, 2, 998244353));
	fflush(stdout);
	return 0;
}