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 <bits/stdc++.h>
using namespace std;

// types - only for stuff used a lot 
using ll = long long;
#define vv vector
#define Pp pair

// IO
#define get(x) scanf("%d",&x)
#define getl(x) scanf("%lld",&x);

// Operations
#define pb push_back
#define pob pop_back
#define sz(a) int(a.size()) 
#define re(a,b) a=max(a,b) // relax
#define ri(a,b) a=min(a,b) // relaxi

// Debugging

#ifndef LOCAL
#define cerr if (0) cerr
#else
#define cerr cout
#endif

#define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; }
#define printv(vec)  {for (int _ : vec) cerr<<_<<" "; cerr<<endl;}

const int mod = 998244353, oo = 1e9;
const ll loo = 1e18;

// Functions 
ll modpow(ll a, ll b) {
	ll ans = 1; // faster modpow than recursive
	for (; b; b/=2,a=a*a%mod)
		if (b&1) ans = (ans*a)%mod;
	return ans;
}
ll gcd(ll a, ll b) {
	while (a) b%=a,swap(a,b);
	return b;
}
#define bitcount __builtin_popcountll
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)


/* 

   ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS

 */

const bool DEBUG = 1;

const int N = 1e6+1;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n; cin>>n;
	int a[n];
	f(i,0,n) cin>>a[i];
	int sieve[N];
	fill(sieve,sieve+N,0);
	f(i,2,N) if (!sieve[i]) {
		sieve[i] = i;
		for (int j = i; j < N; j += i)
			sieve[j] = i;
	}

	auto fac = [&](int i) {
		int cnt = 0;
		while (i>1 && ++cnt) {
			int p = sieve[i];
			if (i%(p*p) == 0) return -1;
			i /= p;
		}
		return cnt&1;
	};

	auto add = [&](ll &a, ll b) {
		a += b;
		if (a>=mod) a-=mod;
	};

	ll sum[N], prodSum[N];
	f(i,0,N) sum[i] = prodSum[i] = 0;

	f(i,0,n) {
		if (sum[a[i]])
			add(prodSum[a[i]],sum[a[i]]*a[i]%mod);
		add(sum[a[i]],a[i]);
	}

	f(i,1,N) {
		for (int j = i+i; j < N; j+=i) {
			if (sum[j]) {
				add(prodSum[i],sum[i]*sum[j]%mod);
				add(prodSum[i],prodSum[j]);
			}
			add(sum[i],sum[j]);
		}
	}

	ll ans = 0;

	f(i,1,N) {
		for (int j = i+i; j < N; j+=i) {
			int ff = fac(j/i);
			if (ff == 1) {
				add(prodSum[i],mod-prodSum[j]);	
			}
			else if (ff == 0) {
				add(prodSum[i],prodSum[j]);
			}
		}	
		add(ans,prodSum[i]*modpow(i,mod-2));
	}

	cout << ans << endl;
	

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}