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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()s[]
#define hell        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--) 
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define MAXN        200001
#define ordered_set tree<pair<ll int,ll int>, null_type,less<pair<ll int,ll int>>, rb_tree_tag,tree_order_statistics_node_update>
ll expo(ll base, ll exponent, ll mod) {                                //return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}
vector <ll int> v[1000001];
ll int value[1000001];
ll int value1[1000001];
ll int ans1[1000001];
int main()
{
    ll int n;
    cin >> n;
    rep(i,1,n+1)
    {
        ll int a;
        cin >> a;
        rep(j,1,sqrt(a)+1)
        {
            if (j>sqrt(a)) continue;
            if (a%j==0)
            {
                v[j].push_back(a);
                if (j!=a/j)v[a/j].push_back(a);
            }
        }
    }

    repr(i,1000000,0)
    {
        if (v[i].empty())
        {
            value[i]=0;
            value1[i]=0;
            continue;
        }
        ll int sum1=0;
        ll int square1=0;
        for (auto j: v[i])
        {
            sum1=(sum1+j)%hell;
            square1=(square1+j*j)%hell;
        }
        value[i]=(sum1*sum1)%hell;
        value1[i]=square1;
    }
    ll int ans=0;
    repr(i,1000000,0)
    {
        ll int inv=expo(i,hell-2,hell);
        ans1[i]=(((value[i]-value1[i]+hell)%hell)*inv)%hell;
        for (ll int j=2*i;j<=1000000;j=j+i)
        {
            ans1[i]=(hell+ans1[i]-((ans1[j]*j)%hell*inv)%hell)%hell;
        }
    }
    rep(i,1,1000001)
    {
        ans=(ans+ans1[i])%hell;
    }
    cout << ans/2 << endl;
}