PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000248. Dãy số khác thường (Unusual Sequences)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy số khác thường (Unusual Sequences)
Unusual Sequences
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , count nonempty finite sequences of positive integers with and . Two sequences differ if their lengths or a corresponding element differ. Output the answer modulo .
Input
One line contains positive integers .
Output
Print the number of valid sequences modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
3 9
Output
3
Explanation
For , , after division by , there are 3 ordered compositions with GCD .
Example 2
Input
5 8
Output
0
Explanation
For , , the sum is not divisible by the required GCD, hence no sequence exists.