#GL0000352. Đếm số thần kỳ (Magic Numbers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm số thần kỳ (Magic Numbers)
Magic Numbers
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A positive integer is -magic when digit occurs at every even position of its decimal representation (positions counted from the left, starting at 1) and at no odd position. Leading zeros are forbidden.
For , 1626 is -magic, while 1666 is not: its third digit is 6. Given , a digit , and positive integers with the same number of digits, count the -magic numbers in inclusive range divisible by . Output the count modulo .
The bounds may contain up to 2000 digits; read them as strings.
Input
- First line: and .
- Second line: decimal integer .
- Third line: decimal integer .
Output
One integer: the count modulo .
Subtasks
- Subtask 1 (20 points): $1 <= m <= 20, 0 <= d <= 9, 1 <= |a|=|b| <= 6, 1 <= a <= b$.
- Subtask 2 (30 points): $1 <= m <= 300, 0 <= d <= 9, 1 <= |a|=|b| <= 250, 1 <= a <= b$.
- Subtask 3 (50 points): $1 <= m <= 2000, 0 <= d <= 9, 1 <= |a|=|b| <= 2000, 1 <= a <= b$.
Examples
Example 1
Input
2 6
10
99
Output
8
Explanation
The eight values are 16, 26, 36, 46, 56, 76, 86, and 96: the second digit is 6, the first is not, and each is even.
Example 2
Input
2 0
1
9
Output
4
Explanation
With one digit, position 1 is odd and cannot be 0; the even numbers 2,4,6,8 qualify.
Example 3
Input
19 7
1000
9999
Output
6
Explanation
The six valid integers are 1767, 2717, 5757, 6707, 8797, and 9747.