PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000240. Đếm dãy có ít nhất hai cách xóa hợp lệ (Counting Arrays)
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ó ít nhất hai cách xóa hợp lệ (Counting Arrays)
Đếm dãy có ít nhất hai cách xóa hợp lệ (Counting Arrays)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given , consider arrays of every length with entries from . An element at its current 1-indexed position can be removed if its GCD with is 1, and remaining elements shift left. Count arrays admitting at least two distinct complete removal-position sequences, modulo .
Input
One line with .
Output
Print the number of ambiguous arrays modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
2 3
Output
6
Explanation
All 6 ambiguous arrays have length two, and length-one arrays never have two distinct deletion orders.
Example 2
Input
4 2
Output
26
Explanation
Among arrays, exactly four have a unique deletion sequence.