#R158E. [ABC158E] Divisible Substring
[ABC158E] Divisible Substring
Score : points
Problem Statement
Takahashi has a string of length consisting of digits from 0 through 9.
He loves the prime number . He wants to know how many non-empty (contiguous) substrings of - there are of them - are divisible by when regarded as integers written in base ten.
Here substrings starting with a 0 also count, and substrings originated from different positions in are distinguished, even if they are equal as strings or integers.
Compute this count to help Takahashi.
Constraints
- consists of digits.
- is a prime number.
Input
Input is given from Standard Input in the following format:
Output
Print the number of non-empty (contiguous) substrings of that are divisible by when regarded as an integer written in base ten.
4 3
3543
6
Here = 3543. There are ten non-empty (contiguous) substrings of :
3: divisible by .35: not divisible by .354: divisible by .3543: divisible by .5: not divisible by .54: divisible by .543: divisible by .4: not divisible by .43: not divisible by .3: divisible by .
Six of these are divisible by , so print .
4 2
2020
10
Here = 2020. There are ten non-empty (contiguous) substrings of , all of which are divisible by , so print .
Note that substrings beginning with a 0 also count.
20 11
33883322005544116655
68