luogu#P7802. [COCI 2015/2016 #6] SAN
[COCI 2015/2016 #6] SAN
Problem Description
has a mysterious infinite table with infinitely many rows and infinitely many columns. Interestingly, each number appears only a finite number of times in the table.
Define the function , which returns the new number obtained by reversing in decimal. For example, , .
The number in row and column of the table is defined as follows:
-
-
$A(i, j) = A(i, j − 1)+\mathrm{rev}\big(A(i,j-1)\big)$,

Now gives queries. Each query provides two integers and . Please find how many numbers in the infinite table have values within .
Input Format
The first line contains an integer .
The next lines each contain two integers and .
Output Format
Output lines, each containing one integer. The -th line should be the answer to the -th query.
2
1 10
5 8
18
8
3
17 144
121 121
89 98
265
25
10
1
1 1000000000
1863025563
Hint
Constraints
For of the testdata, .
For of the testdata, , .
Source
Translated from COCI 2015-2016 CONTEST #6 T6 SAN.
This problem uses the original COCI scoring. Full score is ..
Translated by ChatGPT 5