#P3981. 琅泽难题

    ID: 2893 远端评测题 100ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学递推2017斐波那契,Fibonacci矩阵乘法构造

琅泽难题

Description

The inspiration for this problem comes from the following data:

This data follows the “description method” rule: on the n+1 n+1 -th layer, describe the data of the n n -th layer from left to right. The rule is as follows: starting from the first datum, whenever you encounter a run of a1 a_1 consecutive b1 b_1 , write a1b1 a_1\,b_1 as two new data at the end of the n+1 n+1 -th layer (the “end” here means appended after the last datum; if the n+1 n+1 -th layer has no data yet, then this “end” is the beginning). Then, immediately describe the next run of a2 a_2 consecutive b2 b_2 (b1b2 b_1 \neq b_2 ), and so on, until all data have been fully described. At that point, the n+1 n+1 -th layer is constructed. Here n n is a positive integer.

Now, I have a new idea. Given an initial datum Q Q (the initial datum is on the first layer, and the first layer contains only one datum — the initial datum Q Q ), 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 A A , and on even-numbered layers follow rule B B . See the figure below:

The above shows part of the Langze Array when the initial datum is 1 1 . 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 i i -th layer, how many x x 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 Q Q , i i , and x x , separated by single spaces.

Q Q is the initial datum of the Langze Array.

Output Format

Output a single line with one integer: the count of x x on the i i -th layer.

Since the output can be large, output the result modulo 20171111 20171111 (that is, take the remainder after dividing the original result by 20171111 20171111 ).

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 2 2 on the 2 2 -nd layer is 1 1 .

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