PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000224. Đếm dãy có ƯCLN tiền tố cho trước (Count GCD)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm dãy có ƯCLN tiền tố cho trước (Count GCD)
Count GCD
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given and with , count arrays such that and for every . Two arrays are different if they differ at some index. Print the result modulo .
Input
First line contains ; second line contains integers .
Output
Print the count modulo .
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
3 5
4 2 1
Output
3
Explanation
The first two elements are forced to be and . The third can be 1, 3 or 5, giving exactly three arrays.
Example 2
Input
2 1
1 1
Output
1
Explanation
Since every element lies in [1,1], the only possible array is (1,1).
Example 3
Input
5 50
2 3 5 2 3
Output
0
Explanation
A prefix GCD must divide the preceding prefix GCD. Since 3 does not divide 2, no valid array exists.