PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000349. Đếm dãy chia hết liên tiếp (Mashmokh and ACM)
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 chia hết liên tiếp (Mashmokh and ACM)
Mashmokh and ACM
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Count sequences of length exactly with values in , such that each value divides the following value: .
Equal adjacent values are permitted. Output the number of valid sequences modulo .
Input
One line contains integers and .
Output
Print the count modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
3 2
Output
5
Explanation
The five valid pairs are . In each pair, the first value divides the second.
Example 2
Input
6 4
Output
39
Explanation
Start from ; for each extension, add to whenever divides . The length-four total is 39.