QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 64 MB 總分: 100 难度: [顯示]

#2492. 哈希函数

统计

给定一个哈希函数 $h_n$,它将一个由 $2n$ 位组成的数字 $A$ 加密如下: 令 $A = (a_{2n-1}a_{2n-2} \dots a_1 a_0)_2$,即 $a_i$ 是数字 $A$ 的第 $i$ 位。 数字 $B = (b_{2n-1}b_{2n-2} \dots b_1 b_0)_2$ 也由 $2n$ 位组成,计算方式如下: $b_i = a_i \oplus a_{2i+1}$,对于 $0 \le i < n$, $b_i = a_i \oplus a_{4n-2i-2}$,对于 $n \le i < 2n$, 其中 $\oplus$ 是按位异或(XOR)。换句话说, $B = A \oplus (a_0 a_2 \dots a_{2n-4} a_{2n-2} a_{2n-1} a_{2n-3} \dots a_3 a_1)_2$。

接下来,计算数字 $C = B \oplus \text{RSH}(B)$,它也由 $2n$ 位组成,其中 $\text{RSH}(B)$ 是将 $B$ 循环右移 1 位的结果。换句话说, $C = B \oplus (b_0 b_{2n-1} b_{2n-2} \dots b_2 b_1)_2$。

最后,哈希值计算为 $h_n(A) = 239A + 153C \pmod{2^{2n-1} - 1}$。

例如,令 $n = 4$ 且 $A = 00001101_2 = 13$。 则 $B = 00001101_2 \oplus 11000010_2 = 11001111_2 = 207$。 进一步地,$C = 11001111_2 \oplus 11100111_2 = 00101000_2 = 40$。 最后,$h_4(A) = 239 \times 13 + 153 \times 40 \pmod{2^7 - 1} = 9227 \pmod{127} = 83$。

你的目标是反转这个哈希函数,即给定 $n$ 和 $H$,找到一个 $A$ 使得 $h_n(A) = H$。

输入格式

给定两个整数 $n$ 和 $H$ ($2 \le n \le 16, 0 \le H < 2^{2n-1} - 1$)。 保证输入存在一个 $A$ ($0 \le A < 2^{2n}$) 使得 $h_n(A) = H$。

输出格式

输出一个整数 $A$ ($0 \le A < 2^{2n}$) 使得 $h_n(A) = H$。 如果存在多个这样的 $A$,输出任意一个即可。

样例

输入 1

4 83

输出 1

13

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.