#P3245. [HNOI2016] 大数
[HNOI2016] 大数
Description
Xiao B has a very large number of length ; this number can be regarded as a string of digits and may have leading s, for example, 00009312345. Xiao B also has a prime . Now, Xiao B proposes queries. For each query, within a substring of , count how many of its substrings are multiples of ( is also considered a multiple of ). For example, when is 0077, its substring 007 has substrings: 0,0,7,00,07,007; clearly, all substrings of 007 are multiples of the prime .
Input Format
The first line contains an integer .
The second line contains a digit string .
The third line contains an integer . Then lines follow, each containing two integers , representing a query on the substring of . Note: the leftmost digit of has index ; for example, if is 213567, then is 213.
Output Format
Output lines, each containing one integer. The -th line is the answer to the -th query.
11
121121
3
1 6
1 5
1 4
5
3
2
Hint
Sample 1 Explanation
The first query asks about the entire string. The substrings that satisfy the condition are: 121121,2112,11,121,121.
Constraints
For of the testdata, , , contains only digit characters, and is prime.
Translated by ChatGPT 5
京公网安备 11011102002149号