Language: C++

///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 998244353


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

const int mx = 2e6+123;
vi d[mx];
ll inv[mx], a[mx], T[mx], val[mx];
int vis[mx];

int main()
{
    optimize();
    int lim = 1e6;
    for ( int i = 1; i <= lim; i++ ) inv[i] = modInverse( i );

    for ( int i = 1; i <= lim; i++ ) {
        d[i].clear();
        T[i] = 0;
        vis[i] = 0;
    }

    int n;
    ll sum = 0;

    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
        sum = modAdd( sum, a[i] );
        vis[a[i]]++;
    }

    for ( int i = 1; i <= lim; i++ ) {
        for ( int j = i; j <= lim; j += i ) {
            T[i] = modAdd( T[i], modMul( j, vis[j] ) );
            d[j].PB ( i );
        }
    }


    ll ans = 0;
    for ( int i = 1; i <= n; i++ ) {
        ll sub = 0;

        for ( int j = d[a[i]].size()-1; j >= 0; j-- ) {
            int y = d[a[i]][j];
            for ( int k = d[y].size()-1; k >= 0; k-- ) {
                int dd = d[y][k];
                val[dd] = T[dd];
             //   cnt++;
            }
        }

        for ( int j = d[a[i]].size()-1; j >= 0; j-- ) {
            int y = d[a[i]][j];
            ans = modAdd( ans, modMul( modMul( val[y], inv[y] ), a[i] ) );
            for ( int k = d[y].size()-2; k >= 0; k-- ) {
                int dd = d[y][k];
                val[dd] = modSub( val[dd], val[y] );
                cnt++;
            }
        }
    }

    ans = modSub ( ans, sum );
    ans = modMul( ans, inv[2] );

    cout << ans << endl;
   // cout << cnt << endl;

    return 0;
}


















Compiler output:
a.cc:32:18: warning: overflow in conversion from 'long int' to 'll' {aka 'int'} changes value from '9000000000000000000' to '-494665728' [-Woverflow]
   32 | const ll infLL = 9000000000000000000;
      |                  ^~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:110:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
  110 |                 cnt++;
      |                 ^~~
      |                 int