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 <cstdio>
#include <vector>
using namespace std;

const int M=1000010;
const long long mod=998244353;

void ad(long long &a,long long b){a+=b;a%=mod;}
void mn(long long &a,long long b){a+=mod-b;a%=mod;}
void ml(long long &a,long long b){a*=b;a%=mod;}
long long sq(long long a){return a*a%mod;}
long long pw(long long a,long long n)
{
  return n==0?1ll:sq(pw(a,n/2))*(n%2==1?a:1ll)%mod;
}
long long iv(long long a){return pw(a,mod-2);}

int main()
{
  int n;
  scanf("%d",&n);
  vector<int> T(M,0);
  for(int i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    T[a]++;
  }
  vector<int> mu(M,0);
  for(int p=2;p<M;p++){
    if(mu[p]==0){
      for(int k=p;k<M;k+=p){
	if(mu[k]!=-1){
	  mu[k]++;
	}
      }
      long long p2=(long long)p*p;
      for(long long k=p2;k<M;k+=p2){
	mu[k]=-1;
      }
    }
  }
  vector<long long> f(M,0);
  for(int g=1;g<M;g++){
    long long p=iv(g);
    for(int j=1;g*j<M;j++){
      long long m=(mu[j]==-1?0:mu[j]%2==0?1:mod-1);
      ad(f[g*j],m*p%mod);
    }
  }
  long long ans=0ll;
  for(int d=1;d<M;d++){
    long long S=0,L=0;
    for(int j=d;j<M;j+=d){
      S+=L*T[j]%mod*j%mod;
      S%=mod;
      S+=T[j]*(T[j]-1)/2%mod*j%mod*j%mod;
      S%=mod;
      L+=T[j]*j%mod;
      L%=mod;
    }
    ans+=f[d]*S%mod;
    ans%=mod;
  }
  printf("%lld\n",ans);
  return 0;
}