#P3981. 琅泽难题
琅泽难题
Description
The inspiration for this problem comes from the following data:

This data follows the “description method” rule: on the -th layer, describe the data of the -th layer from left to right. The rule is as follows: starting from the first datum, whenever you encounter a run of consecutive , write as two new data at the end of the -th layer (the “end” here means appended after the last datum; if the -th layer has no data yet, then this “end” is the beginning). Then, immediately describe the next run of consecutive (), and so on, until all data have been fully described. At that point, the -th layer is constructed. Here is a positive integer.
Now, I have a new idea. Given an initial datum (the initial datum is on the first layer, and the first layer contains only one datum — the initial datum ), construct a data array using a rule similar to the one above (the description method), called the “Langze Array.” My rule is: on odd-numbered layers follow rule , and on even-numbered layers follow rule . See the figure below:

The above shows part of the Langze Array when the initial datum is . As for what the exact rules are, that is for you to explore.
However!!!
That is not the final goal. What I want you to find is: on the -th layer, how many are there (we define the layer containing the initial datum as the first layer)?
Input Format
The input contains only one line with three integers , , and , separated by single spaces.
is the initial datum of the Langze Array.
Output Format
Output a single line with one integer: the count of on the -th layer.
Since the output can be large, output the result modulo (that is, take the remainder after dividing the original result by ).
2 2 2
1
2 14 5
12
Hint
Sample 1 explanation:
A (small) part of the constructed Langze Array is:

Therefore, the count of on the -nd layer is .
Notes:
-
All data are integers.
-
If you have no idea how to proceed, you may choose to solve some subproblems first.
-
Constraints for each test point are as follows:

Translated by ChatGPT 5
京公网安备 11011102002149号