#GL0000345. Đếm dãy con thỏa chia hết theo vị trí (Multiplicity)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm dãy con thỏa chia hết theo vị trí (Multiplicity)
Multiplicity
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array . A nonempty subsequence is formed by choosing indices in their original order, with .
The subsequence is good if is divisible by its one-based position for every .
Count all good subsequences modulo . Distinct sets of source indices count as distinct subsequences, even when the selected values are identical.
Input
The first line contains , the second line integers .
Output
Print the number of good subsequences modulo .
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Example 1
Input
2
1 2
Output
3
Explanation
There are exactly three nonempty subsequences: [1], [2], and [1,2]. In the length-two subsequence the second value 2 is divisible by position 2.
Example 2
Input
5
2 2 1 22 14
Output
13
Explanation
There are 5 valid length-one subsequences and 8 valid length-two subsequences; none longer. Thus the answer is 13.