#P3281. [SCOI2013] 数数
[SCOI2013] 数数
Description
Fish is a fish living in the sea. One day he felt bored and started a counting game. The detailed rules are:
-
Fix a base for counting.
-
Fix an interval .
-
For each number in , regard the number as a string, and list the value in base of each (contiguous) substring of that string.
-
Sum all the listed numbers. Now Fish has finished one round of counting, but he is not sure whether his result is correct. Since is large, he does not have the extra energy to verify it. Can you write a program to help him verify it?
Input Format
The input contains three lines.
The first line contains only one number , which is the base for counting.
The second line contains numbers. The first number is , meaning that the length of in base is . The next numbers, from the most significant digit to the least significant digit, represent each digit of .
The third line contains numbers. The first number is , meaning that the length of in base is . The next numbers, from the most significant digit to the least significant digit, represent each digit of .
Output Format
Output exactly one line: the result according to Fish’s counting rules, expressed in base . Since the number can be large, output the result modulo .
In the testdata, there may be cases where . In such cases, the output is .
10
3 1 0 3
3 1 0 3
120
Hint
Sample Explanation:
contains only the number 103. All its substrings include 1, 10, 103, 0, 03, 3, and their sum is 120.
Constraints:
of the testdata: .
of the testdata: .
of the testdata: .
Translated by ChatGPT 5
京公网安备 11011102002149号