#P7575. 「PMOI-3」公约数

「PMOI-3」公约数

Problem Description

Given nn, mm, and a sequence xx of length n1n-1, it is guaranteed that all xix_i are pairwise distinct.

Compute

$$\sum_{i_1=1}^m\sum_{i_2=1}^m\cdots\sum_{i_n=1}^m[\gcd(i_1,i_2)=x_1][\gcd(i_2,i_3)=x_2]\cdots[\gcd(i_{n-1},i_n)=x_{n-1}]$$

Output the answer modulo 998244353998244353.

Input Format

The first line contains two integers nn and mm.

The next line contains n1n-1 integers, representing xix_i.

Output Format

Output one integer in a single line.

3 2
1 2
1
5 20
1 2 4 6
312
5 20
2 3 1 4
592
10 1000
1 2 4 8 16 32 64 128 256 
207388829

Hint

[Sample Explanation]

For the first sample, the condition is satisfied only when i1=1i_1=1, i2=2i_2=2, and i3=2i_3=2.

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (10 pts): n,m5n, m \le 5.
  • Subtask 2 (15 pts): n,m500n, m \le 500.
  • Subtask 3 (15 pts): n,m5×103n, m \le 5\times 10^3.
  • Subtask 4 (15 pts): n,m5×104n, m \le 5\times 10^4.
  • Subtask 5 (20 pts): n,m3×105n, m \le 3\times 10^5.
  • Subtask 6 (25 pts): no special constraints.

For 100%100\% of the testdata, n1mn-1 \le m, 1n,m1061 \le n, m \le 10^6, 1xim1 \le x_i \le m, and all xix_i are pairwise distinct.

Translated by ChatGPT 5