#P7575. 「PMOI-3」公约数
「PMOI-3」公约数
Problem Description
Given , , and a sequence of length , it is guaranteed that all 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 .
Input Format
The first line contains two integers and .
The next line contains integers, representing .
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 , , and .
[Constraints]
This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (15 pts): .
- Subtask 3 (15 pts): .
- Subtask 4 (15 pts): .
- Subtask 5 (20 pts): .
- Subtask 6 (25 pts): no special constraints.
For of the testdata, , , , and all are pairwise distinct.
Translated by ChatGPT 5