//#pragma GCC optimise("Ofast,unroll-loops,no-stack-protector,fast-math");
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
          
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
          
using namespace std;
using namespace __gnu_pbds;
          
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
          
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
          
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define int long long
 
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("chess.in", "r", stdin);
    //freopen("chess.out", "w", stdout);
    #endif
}

const ll mod = 998244353;
const int MAXN = 1e6 + 100;
ll inv[MAXN], cnt[MAXN], sum[MAXN], sum1[MAXN];

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

signed main() {
    FAST_IO();
    for (int i = 1; i < MAXN; ++i) {
        inv[i] = binpow(i, mod - 2);
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    for (int i = 0; i < MAXN; ++i) {
        if (cnt[i] == 0) {
            continue;
        }
        for (int j = 1; j * j <= i; ++j) {
            if (i % j == 0) {
                sum[j] = (sum[j] + cnt[i] * (i / j)) % mod;
                if (i / j != j) {
                    sum[i / j] = (sum[i / j] + cnt[i] * (j)) % mod;
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < MAXN; ++i) {
        if (cnt[i] == 0) {
            continue;
        }
        ll val = ((cnt[i] * (cnt[i] - 1)) / 2) % mod;
        ans = (ans + 2 * val * i) % mod;
        vector<int> d;
        for (int j = 1; j * j <= i; ++j) {
            if (i % j == 0) {
                d.push_back(j);
                if (i / j != j) {
                    d.push_back(i / j);
                }
            }
        }
        sort(all(d));
        int sz = d.size();
        for (int j : d) {
            sum1[j] = (sum[j] - cnt[i] * (i / j) + mod * mod) % mod;
        }
        for (int pt = sz - 1; pt >= 0; --pt) {
            for (int pt1 = pt + 1; pt1 < sz; ++pt1) {
                if (d[pt1] % d[pt] == 0) {
                    ll tmp = (sum1[d[pt1]] * d[pt1]) % mod;
                    tmp = (tmp * inv[d[pt]]) % mod;
                    sum1[d[pt]] -= tmp;
                    if (sum1[d[pt]] < 0) {
                        sum1[d[pt]] += mod;
                    }
                }
            }
        }
        for (int j : d) {
            ll tmp = (sum1[j] * i) % mod;
            tmp = (tmp * cnt[i]) % mod;
            ans += tmp;
            if (ans >= mod) {
                ans -= mod;
            }
        }
    }
    cout << (ans * inv[2]) % mod << '\n';
} 

Measured memory_bytes: 31488