#P10049. [CCPC 2023 北京市赛] 报数 IV
[CCPC 2023 北京市赛] 报数 IV
Background
This is the fourth time that Little R and Little Z have played the counting-off game, so they decided not to write a long problem statement anymore. You only need to know that they came up with another strange counting rule, and they want to figure out which numbers can be called out.
Problem Description
For any positive integer , define the function as the sum of all digits of in decimal. For example, . Clearly, is also a positive integer, so we can consider nested applications such as , , and so on. Furthermore, for positive integers , define (with a total of layers of ).
To make the counting-off game different each round, Little R and Little Z decide to set two positive integers for each round, and specify that: in this round, all positive integers satisfying cannot be called out.
Since both of them are skilled players, to prevent the game from going on forever, each round also gives a positive integer as the upper bound of counting off. They want to know: among the positive integers not exceeding , how many cannot be called out under this rule.
Input Format
The first line contains a positive integer , indicating the number of game rounds played by Little R and Little Z. It is guaranteed that .
The next lines each contain three positive integers , describing one round of the game as stated above. It is guaranteed that , .
Output Format
Output lines. Each line contains one integer, representing the number of integers that cannot be called out in this round, modulo .
2
114 1 5
514 2 10
8
10
Hint
In the first round, the numbers that cannot be called out are .
Translated by ChatGPT 5