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<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
#include <cstdint>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


//II→factorialを計算するrange
constexpr ll MOD = 998244353;
template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};


int main(void){
      int n;
      cin>>n;
      int a[n];
      rep0(i,n) cin>>a[i];
      constexpr int V=1e6+1;
      vector<modint<MOD>> w(V+2,0);
      vector<modint<MOD>> c(V+3,0);
      vector<modint<MOD>> s(V+3,0);
      vector<modint<MOD>> sum1(V+3,0);
      vector<modint<MOD>> sum2(V+3,0);
      constexpr modint<MOD> I=1;
      constexpr modint<MOD> II=2;
      w[0]=0;
      for(int i=1;i<V;i++){
            modint<MOD> j=i;
            w[i]=I/j;
      }
      for(int i=1; i<V;i++){
            for(int j=2*i;j<V;j+=i){
                  w[j]-=w[i];
            }
      }
      for(int i=0;i<n;i++){
            c[a[i]]+=I;
      }
      for(int d=1;d<V;d++){
            for(int j=d;j<V;j+=d){
              if(c[j].a==0) continue;
                  modint<MOD> l=j;
                  sum1[d]+=(l*c[j]);
            }
      }
      for(int d=1;d<V;d++){
            for(int j=d;j<V;j+=d){
              if(c[j].a==0) continue;
                  modint<MOD> l=j;
                  sum2[d]+=(l*l*(c[j]*(c[j]+1))/II);
            }
      }
      for(int d=1;d<V;d++){
            s[d]=((sum1[d]*sum1[d])-sum2[d])/II;
      }
      modint<MOD> ans=0;
      for(int d=1;d<V;d++){
            ans+=w[d]*s[d];
      }
      cout<<ans.a<<endl;
      return 0;
}