Hash Function

시간 제한3초메모리 제한1024 MB

요약
n과 목표 해시값 H가 주어질 때, XOR 기반 해시와 순환 시프트, 나머지 연산을 거쳐 H가 나오는 2n비트 A를 찾는다.
난이도

보통10점 중 7점

유형
비트 연산, 완전 탐색, 수학, 구현
정답자
아직 제출이 없습니다

문제

A hash function h_nh\_n is given, which encrypts the number AA, consisting of 2n2n bits, as follows:

Let A=(a_2n−1a_2n−2⋯a_1a_0)_2A = (a\_{2n-1}a\_{2n-2} \cdots a\_1a\_0)\_2, that is, a_ia\_i is the ii-th bit of the number AA.

The number B=(b_2n−1b_2n−2⋯b_1b_0)_2B = (b\_{2n-1}b\_{2n-2} \cdots b\_1b\_0)\_2, also consisting of 2n2n bits, is calculated as follows: b_i=a_i⊕a_2i+1, for 0≤i<n,b\_i = a\_i \oplus a\_{2i+1},\text{ for } 0 \le i < n, b_i=a_i⊕a_4n−2i−2, for n≤i<2n,b\_i = a\_i \oplus a\_{4n-2i-2},\text{ for } n \le i < 2n, where ⊕\oplus is bitwise exclusive OR (XOR). In other words, B=A⊕(a_0a_2⋯a_2n−4a_2n−2a_2n−1a_2n−3⋯a_3a_1)_2.B = A \oplus (a\_0a\_2 \cdots a\_{2n-4}a\_{2n-2}a\_{2n-1}a\_{2n-3} \cdots a\_3a\_1)\_2.

Next, the number C=B⊕RSH(B)C = B \oplus \text{RSH}( B ) is calculated, also consisting of 2n2n bits, where RSH(B)\text{RSH}(B) is a cyclic right shift by 11 bit. In other words, C=B⊕(b_0b_2n−1b_2n−2⋯b_2b_1)_2.C = B \oplus (b\_0b\_{2n-1}b\_{2n-2} \cdots b\_2b\_1)\_2.

Finally, the hash value is calculated as h_n(A)=239A+153C mod (22n−1−1)h\_n(A) = 239 A + 153 C \bmod (2^{2n-1}-1).

For example, let n=4n=4 and A=00001101_2=13A = 00001101\_2 = 13.

Then, B=00001101_2⊕11000010_2=11001111_2=207B = 00001101\_2 \oplus 11000010\_2 = 11001111\_2 = 207.

Further, C=11001111_2⊕11100111_2=00101000_2=40C = 11001111\_2 \oplus 11100111\_2 = 00101000\_2 = 40.

Finally, h_4(A)=239×13+153×40 mod (27−1)=9,227 mod 127=83h\_4(A) = 239 \times 13 + 153 \times 40 \bmod (2^7-1) = 9\\,227 \bmod 127 = 83.

Your goal is to invert this hash function, that is, for given nn and HH, find AA such that h_n(A)=Hh\_n(A)=H.

입력

You are given two integers nn and HH (2≤n≤162 \le n \le 16, 0≤H<22n−1−10 \le H < 2^{2n-1}-1).

It is guaranteed that for the input there exists AA (0≤A<22n0 \le A < 2^{2n}) such that h_n(A)=Hh\_n(A)=H.

출력

Print one integer AA (0≤A<22n0 \le A < 2^{2n}) such that h_n(A)=Hh\_n(A)=H.

If there are several such AA --- output any.

예제1

  1. 예제 1

    입력
    4 83
    
    예상 출력
    13