#P16213. [ECUSTPC 2025] 十六号塔
[ECUSTPC 2025] 十六号塔
Problem Description
Maddy came to a faded tall tower. On the stone tablet under the tower, there was a number carved on it.
Maddy found a mechanism on a stone nearby. She pressed it and found that the number on the tablet changed as follows:
- Split the decimal representation of into digits, square each digit, and then concatenate them in the original order to form a new number .
Maddy was curious. She pressed the mechanism times. She recorded the original and the results after pressing it these times, for a total of numbers: .
Maddy wants to know the value of the sum of these numbers modulo . Please help her compute it.
Input Format
The first line contains an integer (), the number of test cases.
For each test case, the only line contains two integers and (), representing the number carved on the tablet and the number of times Maddy pressed the mechanism.
Output Format
For each test case, output one integer on a single line, representing the sum of the above results modulo .
4
1 100
2 4
74700 1
2279 1
2
6
6
5
Hint
Sample 1 Explanation
For the 1st sample case, after pressing the mechanism, always stays . Each result is , so the total sum is , and the modulo is .
For the 2nd sample case, the number changes as follows: , , , . The sum of these 5 numbers modulo is $(2 + 4 + 16 + 136 + 1936) \bmod 9 = 2094 \bmod 9 = 6$.
For the 3rd sample case, the number changes as follows: .
For the 4th sample case, the number changes as follows: .
Hint
Taking modulo means the remainder after dividing the number by .
Translated by ChatGPT 5