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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const int maxn=1000005,tt=998244353;
int qsm(LL w,int b){LL num=1;while(b){if (b&1) num=num*w%tt;w=w*w%tt;b>>=1;}return num;}
int NI[maxn],n,a[maxn],m,w[maxn],sum[maxn];
LL ans;
inline int _read(){
	int num=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') num=num*10+ch-48,ch=getchar();
	return num;
}
int main(){
	n=_read();for (int i=1;i<=n;i++) a[i]=_read(),m=max(m,a[i]),sum[a[i]]++;
	for (int i=1;i<=m;i++) NI[i]=qsm(i,tt-2);
	for (int i=1;i<=m;i++){
		w[i]=(w[i]+NI[i])%tt;
		for (int j=i*2;j<=m;j+=i) w[j]=(w[j]-w[i]+tt)%tt;
	}
	for (int i=1;i<=m;i++){
		LL num1=0,num2=0;
		for (int j=i;j<=m;j+=i) num1+=(LL)sum[j]*j%tt,num2+=sum[j]*j%tt*j%tt;
		num1%=tt;num2%=tt;
		ans+=w[i]*((num1*num1-num2+tt)%tt)%tt;
	}
	printf("%lld\n",ans%tt*NI[2]%tt);
	return 0;
}