#P10262. [GESP样题 六级] 亲朋数
[GESP样题 六级] 亲朋数
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1106.
Problem Description
You are given a digit string of length , consisting of digits . It is easy to see that it has contiguous substrings in total. If the number represented by a substring (leading zeros are allowed) is a multiple of , then this substring is called a “friendly substring” of the digit string with respect to .
For example, if the digit string is “ ” and , then among the contiguous substrings, the friendly substrings are “ ”, “ ”, “ ”, “ ”, “ ”, “ ”, “ ”, “ ”, “ ”, “ ”, and “ ”, for a total of . Note that “ ” appears times, but since they occur at different positions in , they are counted as different friendly substrings.
Now, given the digit string and a positive integer , can you compute how many friendly substrings there are?
Input Format
The first line contains a positive integer . It is guaranteed that .
The second line contains a digit string of length . It is guaranteed that .
Output Format
Output one line containing one integer, representing the answer.
2
102
5
2
12342
11
Hint
Sample 1 Explanation
There are friendly substrings: , , , , and .
Translated by ChatGPT 5