Very interesting, you can carefully appreciate the problem, see White is Mo Team board.
Description
Small B has a large number of S, the length reached N bits; This number can be seen as a string, it may have a leading 0, for example 00009312345
。 Small B also has a prime number p. Now, small B raises M queries, and each query asks how many substrings in a substring of S are multiples of P (0 Also
is a multiple of P). For example, S is 0077, its substring 007 has 6 substrings: 0,0,7,00,07,007; obviously 0077 of the substring 007 has 6 substrings are all vegetarian
Multiples of 7.
Input
The first line is an integer: P. The second line is a string: S. The third line is an integer: M. The next m line, two integers per line fr,to, represents the
Sub-string s[fr...to]. Note: The leftmost number of S has a position ordinal of 1; For example, S is 213567, then s[1] is 2,s[1 ... 3] is 2
13. N,m<=100000,p as prime number
Output
Output m lines, one integer per line, and line I is the answer to the I query.
Problem analysis
An interval [l,r] produces a contribution that is _{i,j}\equiv 0\ ({\rm mod}\ p) $.
according to common routines, the interval should be split into a formula about the endpoint. Use $pre[i]$ to represent the value of the former $i$ bit in decimal, then _{i,j}=pre[j]-10^{j-i+1}*pre[i-1]$
"Mo Team" bzoj4542: [Hnoi2016] Large number