#GL0000332. Đếm dãy con có bội chung nhỏ nhất bằng M (Subsequence LCM)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm dãy con có bội chung nhỏ nhất bằng M (Subsequence LCM)
Subsequence LCM
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers and a positive integer . Count the ways to select at least one position such that the least common multiple (LCM) of all selected elements is exactly .
The selected positions need not be contiguous; their original order is preserved. Different sets of positions are counted separately, even when their selected values are identical. The LCM of a one-element sequence is that element.
Print the count modulo .
Input
The first line contains ; the second contains .
Output
Print the number of valid subsequences modulo .
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Example 1
Input
4 6
2 3 4 6
Output
5
Explanation
The value cannot appear since it does not divide . The valid selections are , , , and : five ways.
Example 2
Input
5 349
1 1 1 1 349
Output
16
Explanation
The element must be selected, while each of the four ones may independently be included or excluded: .
Example 3
Input
16 720720
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Output
2688
Explanation
Since , the values are mandatory. Choose a nonempty subset of and a nonempty subset of to supply and . Each of the remaining seven positions may be included or skipped. The count is .
Note: Each input file contains one case using the specified format.