#P5885. [CTSC2014] 随机数
[CTSC2014] 随机数
Problem Description
Lulu, Huahua, and Xuanxuan have recently become interested in random numbers in computers. As is well known, random number sequences generated by computers are not truly random; they are pseudorandom numbers produced by certain rules.
One day, Lulu learned a method for generating random numbers called the Mersenne twister. Given initial parameters , and an initial value , it constructs a pseudorandom sequence by the following recurrence:
$$M_n=\begin{cases}2M_{n-1} & 2M_{n-1}<2^m\\(2M_{n-1}-2^m) \ XOR \ x & 2M_{n-1}\geq 2^m\end{cases}$$Here, is the bitwise exclusive OR operation (the ^ operator in C/C++). If the choice of parameter makes the sequence, as its length tends to infinity, take values in approximately with equal probability, then is called good. For example, when , is obviously not good.
After Lulu introduced the Mersenne twister to her partners, Huahua wanted to use some classic randomness tests to check its randomness strength. For this, Huahua used a computer to compute some .
But careful Xuanxuan noticed that when Huahua entered in binary, she accidentally typed extra ’s at the end. Xuanxuan was about to tell Huahua about this mistake, but Huahua had already computed and recorded the wrong without recording the value of . Although this is not a fatal problem, when Xuanxuan told Huahua about the oversight, the perfectionist Huahua still begged Xuanxuan to help her correct the value of . Xuanxuan then handed this task to her AI—you.
Input Format
- The first line contains a positive integer .
- The second line is the binary representation of (a total of bits, arranged from low bit to high bit).
- The third line is the binary representation of (arranged in the same way as ).
- The fourth line contains an integer .
Next, there are two possible cases:
- (Xuanxuan recorded Huahua’s input): the fifth line contains an integer, meaning the correct value of that Xuanxuan recorded.
- (Xuanxuan failed to record Huahua’s input): the fifth line is , and the sixth line gives the wrong binary representation of computed by Huahua.
Output Format
Only one line: an -bit 01 string, representing the correct you computed (also required to be from low bit to high bit).
10
1 1 1 0 0 1 1 1 0 0
1 1 1 0 0 0 0 0 1 1
0
100
0101111001
Hint
For the part with , either , or .
For the part with , , , , and is good.
Translated by ChatGPT 5