#GL0000341. Đếm cách điền chữ số để dư 5 khi chia 13 (Digits Parade)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm cách điền chữ số để dư 5 khi chia 13 (Digits Parade)
Digits Parade
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a string of digits 0 through 9 and question marks ?.
Replace each question mark with one digit. Leading zeroes are allowed. Different assignments to question-mark positions count separately.
Count the assignments for which the resulting non-negative integer leaves remainder modulo . Print the answer modulo .
Input
One line containing the string .
Output
Print the number of valid assignments modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
??2??5
Output
768
Explanation
For example, 482305, 002865, and 972665 each leave remainder 5 modulo 13. Counting every assignment, including leading zeroes, gives 768.
Example 2
Input
?44
Output
1
Explanation
Only replacement ? = 0 makes 044 (value 44), which leaves remainder 5 modulo 13.
Example 3
Input
7?4
Output
0
Explanation
No replacement produces remainder 5 modulo 13.