#P5885. [CTSC2014] 随机数

    ID: 6635 远端评测题 6000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2014O2优化快速数论变换 NTTCTSC/CTS

[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 mZ+m \in Z+, xZ+[0,2m) x \le Z+\cap[0,2m) and an initial value M0Z+[0,2m)M_0 \in Z+\cap [0,2m), it constructs a pseudorandom sequence {Mn}\{M_n\} 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, XORXOR is the bitwise exclusive OR operation (the ^ operator in C/C++). If the choice of parameter xx makes the sequence, as its length tends to infinity, take values in Z+(0,2m)Z+ \cap (0,2m) approximately with equal probability, then xx is called good. For example, when m>1m>1, x=0x=0 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 MkM_k.

But careful Xuanxuan noticed that when Huahua entered kk in binary, she accidentally typed ll extra 00’s at the end. Xuanxuan was about to tell Huahua about this mistake, but Huahua had already computed and recorded the wrong MkM_k without recording the value of kk. 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 MkM_k. Xuanxuan then handed this task to her AI—you.

Input Format

  • The first line contains a positive integer mm.
  • The second line is the binary representation of xx (a total of mm bits, arranged from low bit to high bit).
  • The third line is the binary representation of M0M_0 (arranged in the same way as xx).
  • The fourth line contains an integer typetype.

Next, there are two possible cases:

  1. type=0type=0 (Xuanxuan recorded Huahua’s input): the fifth line contains an integer, meaning the correct value of kk that Xuanxuan recorded.
  2. type=1type=1 (Xuanxuan failed to record Huahua’s input): the fifth line is ll, and the sixth line gives the wrong binary representation of MkM_k computed by Huahua.

Output Format

Only one line: an mm-bit 01 string, representing the correct MkM_k 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 type=0type=0, either m,k106m,k \le 10^6, or m2000,k1018m \le 2000,k \le 10^{18}.

For the part with type=1type=1, m103m \le 10^3, k1018k \le 10^{18}, l10l \le 10, and xx is good.

Translated by ChatGPT 5