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<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 

typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

struct mint{
    long long x;
    long long mod = 998244353;
    
    mint(): x(0) {}
    mint(long long _x): x(_x) {}
    //operator long long() { return x; }

    mint operator+(const mint & b) const { return (x + b.x) % mod; }
    mint operator-(const mint & b) const { return (x - b.x + mod) % mod; }
    mint operator*(const mint & b) const { return (x * b.x) % mod; }

    template<class T>
    mint operator^(T b) const {
        if(!b) return 1;
        mint tmp = (*this) ^ (b / 2);
        return b % 2 ? tmp * tmp * (*this) : tmp * tmp;
    }

    mint inv() const { 
        static unordered_map<long long, long long> inv_dp;
        if(inv_dp.count(x))
            return inv_dp[x];
        else if(inv_dp.size() < 1000000)
            return mint(inv_dp[x] = ((*this) ^ (mod - 2)).x);
        else return (*this) ^ (mod - 2);
    }
    
    mint operator/(const mint & b) const { return (*this) * b.inv(); }
};

const int MAXN = 2e5 + 20, MAXM = 1e6 + 10;
int n, m = 1e6;
long long a[MAXN];
mint w[MAXM];
int cnt[MAXM] = {};

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    }

    m = *max_element(a, a + n);


    for(int i = 1; i <= m; i++)
    	w[i] = mint(1) / mint(i);
    for(int i = 1; i <= m; i++) {
    	for(int j = 2; j <= m / i; j++) {
    		w[i * j] = w[i * j] - w[i];
    	}
    }

    for(auto x : a)
    	cnt[x]++;

    mint res = 0;
    for(int i = m; i >= 1; i--) {
    	mint tmp = 0;
    	for(int j = 1; j <= m / i; j++) {
    		tmp = tmp + mint(cnt[i * j] * i * j);
    	}
    	res = res + w[i] * tmp * tmp;
    }
    for(auto x : a)
    	res = res - mint(x);
    res = res / mint(2);
    cout << res.x << endl;


    return 0;
}