#P10791. 『SpOI - R1』强大到让你们所有人注视
『SpOI - R1』强大到让你们所有人注视
Problem Description
This problem contains multiple test cases.
You are given an -digit base- big number.
Let denote the new base- number formed by taking the digits from the -th to the -th digit (from most significant to least significant) of this base- number.
You need to compute . Note that this summation is also done in base .
Since the answer may be very large, let be when written in base . You only need to output the result of the answer modulo .
Reminder again: all summations, operations, and modulo in this problem are done in base .
Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains two positive integers , describing this big number.
The second line of each test case contains a sequence , which gives each digit of this base- big number from most significant to least significant. It is guaranteed that .
Output Format
For each test case, output one line: the answer modulo . Since it is also a base- number, output each digit in order separated by spaces.
Note that your output should not contain leading zeros.
1
3 2
1 1 0
1 1 0 1
1
2 20070721
20070720 1
2
Hint
Explanation for Sample #1
All are: . Adding them in base gives , and then taking modulo in base yields the answer .
Explanation for Sample #2
For this number, is clearly divisible by . After dividing and by , both remainders are . Therefore, the answer after modulo is .
Constraints
This problem uses bundled subtasks and subtask dependencies.
For of the testdata, , , , . The base- big number may contain leading zeros.
| Subtask | Special Properties | Score | Dependencies | ||
|---|---|---|---|---|---|
| 1 | None | None | |||
| 2 | |||||
| 3 | None | 1,2 | |||
| 4 | 1,2,3 |
Translated by ChatGPT 5