PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000271. Tổng bội chung nhỏ nhất của các cặp (LCMs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng bội chung nhỏ nhất của các cặp (LCMs)

LCMs

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of NN positive integers A1,A2,…,ANA_1,A_2,\ldots,A_N. For every pair of different positions (i,j)(i,j) such that 1≤i<j≤N1\le i<j\le N, consider the least common multiple lcm⁡(Ai,Aj)\operatorname{lcm}(A_i,A_j).

Compute the sum of these least common multiples over all position pairs. Even if two positions contain equal values, their pair must still be counted exactly once. Print the answer modulo 998244353998244353.

Input

  • The first line contains an integer NN, the length of the sequence.
  • The second line contains exactly NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N in sequence order.

Output

Print one integer, $\displaystyle\sum_{1\le i<j\le N}\operatorname{lcm}(A_i,A_j)$ modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 1≤N≤801\le N\le 80; 1≤Ai≤1001\le A_i\le 100 for each 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤N≤40001\le N\le 4000; 1≤Ai≤500001\le A_i\le 50000 for each 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Ai≤10000001\le A_i\le 1000000 for each 1≤i≤N1\le i\le N.

Examples

Example 1

Input

3
2 4 6

Output

22

Explanation

There are three pairs: the LCMs of (2,4)(2,4), (2,6)(2,6), and (4,6)(4,6) are 44, 66, and 1212, respectively. Thus the answer is 4+6+12=224+6+12=22.

Example 2

Input

8
1 2 3 4 6 8 12 12

Output

313

Explanation

The eight positions give 2828 distinct pairs. The values 1212 at positions 7 and 8 still form a valid pair with LCM 1212. Grouping the contributions by the first position gives the following sums:

  • Position 1 (value 11): 4747.
  • Position 2 (value 22): 4848.
  • Position 3 (value 33): 6666.
  • Position 4 (value 44): 4444.
  • Position 5 (value 66): 4848.
  • Position 6 (value 88): 4848.
  • Position 7 (value 1212): 1212.

Their total is 47+48+66+44+48+48+12=31347+48+66+44+48+48+12=313.

Example 3

Input

10
356822 296174 484500 710640 518322 888250 259161 609120 592348 713644

Output

353891724

Explanation

There are 4545 pairs of positions. Evaluate each pair using lcm⁡(x,y)=xy/gcd⁡(x,y)\operatorname{lcm}(x,y)=xy/\gcd(x,y) and sum all contributions modulo 998244353998244353. This gives 353891724353891724. Use a sufficiently wide integer type or modular arithmetic to avoid overflow.