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: Time Limit Exceeded)

#define debug_switch
#ifdef debug_switch
#define debug if(1) puts("debug");
#define dout if(1) cout
#else
#define debug if(0) puts("debug");
#define dout if(0) cout
#endif
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-7;
using namespace std;
bool vis[N];
int prime[N],pnum=0,mu[N];//,sum[N];
void Mobius()
{
	//memset(vis,0,sizeof vis);
	vis[0] = vis[1] = mu[1] = 1;
	for(int i = 2; i < N; i++){
		if(!vis[i]){
			prime[++pnum] = i;
			mu[i] = -1;
		}
		for(int j = 1;j <= pnum && prime[j]*i < N; j++){
			vis[prime[j]*i] = 1;
			if(i % prime[j] == 0){
				mu[prime[j]*i] = 0;
				break;
			}
			mu[prime[j]*i] = -mu[i];
		}
	}
//	for(int i = 1;i < N; i++)  //求前缀和，用于分块优化
//		sum[i] = sum[i-1] + mu[i];
}
int cnt[N];
int nn = 1e6;
map<int,int> mp;
ll cal(int x){
	if(mp.count(x))return mp[x];
	ll res=0;
//	for(int i=x;i<=nn;i+=x){
//		res = (res + 1ll * (i/x) * cnt[i] % mod) % mod;
//	}
	for(int i=1;i<=nn/x;i++){
		res = (res + 1ll * i * cnt[i*x] % mod) % mod;
	}
	return mp[x] = res * res % mod;
}
ll qpow(ll a, int n){
	ll res=1;
	while(n){
		if(n&1)res=res*a%mod;
		a = a*a%mod;
		n >>= 1;
	}
	return res;
}
int main()
{
	int n,x;
	ll sum=0;
	Mobius();
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		sum += x; 
		cnt[x]++;
	}
	sum %= mod;
	ll ans=0;
	for(int i=1;i<=nn;i++){
		ll tmp=0;
		for(int j=1;j<=nn/i;j++){
			if(mu[j])
				tmp = (tmp + 1ll * mu[j] % mod * j % mod * j % mod * cal(1ll*i*j) % mod) % mod;
		}
		//cout<<tmp<<endl;
		ans = (ans + tmp * i % mod) % mod;
		//cout<<ans<<endl;
	}
	ans = ((ans - sum) % mod + mod) % mod;
	cout<<(ans * qpow(2, mod-2) % mod)<<endl;
	return 0;
}