PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000327. Các dãy chia hết liên tiếp (Multiple 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
Các dãy chia hết liên tiếp (Multiple Sequences)
Multiple Sequences
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers and , count sequences of integers satisfying:
- for every ;
- is divisible by for every (equality is allowed).
Two sequences are different if at least one position differs. Output the count modulo .
Input
A single line containing .
Output
Print the count of valid sequences modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): .
Examples
Example 1
Input
3 4
Output
13
Explanation
Group by the final term : the numbers of valid sequences ending in are respectively . Their sum is .
Example 2
Input
20 30
Output
71166
Explanation
Summing the combinatorial counts for all final terms from to gives modulo .
Example 3
Input
200000 200000
Output
835917264
Explanation
This case reaches both maximum bounds; prime factorization and modular combinations are required instead of enumerating sequences.