#P15837. [蓝桥杯第一届国际赛] 希尔伯特曲线

[蓝桥杯第一届国际赛] 希尔伯特曲线

Problem Description

A Hilbert curve is a recursively defined curve. An nn-order Hilbert curve is defined on a 2n×2n2^n \times 2^n grid. The 1st-order curve is as follows:

:::align{center} :::

The 2nd-order curve is as follows:

:::align{center} :::

The 3rd-order curve is as follows:

:::align{center} :::

An nn-order Hilbert curve can be seen as a curve that starts from the lower-left corner, passes through all grid cells, and ends at the lower-right corner.

We define the coordinates of the lower-left cell as (0,0)(0,0), and the coordinates of the lower-right cell as (2n−1,0)(2^n - 1, 0). Then we can list, in order, the coordinates of the cells that the curve passes through.

For example, the 1st-order Hilbert curve passes through the cells in the following order: (0,0),(0,1),(1,1),(1,0)(0,0), (0,1), (1,1), (1,0). The 2nd-order Hilbert curve passes through the cells in the following order: $(0,0), (1,0), (1,1), (0,1), (0,2), (0,3), (1,3), (1,2), (2,2), (2,3), (3,3), (3,2), (3,1), (2,1), (2,0), (3,0)$.

Given n,pn, p, find the coordinates of the pp-th point that the nn-order Hilbert curve passes through.

Input Format

The input contains one line with two integers n,pn, p.

Output Format

Output one line with two integers separated by a single space, representing the required coordinates.

2 5
0 2

Hint

Constraints

For 30%30\% of the testdata, 1≤n≤101 \le n \le 10, 1≤p≤1041 \le p \le 10^4.

For 50%50\% of the testdata, 1≤n≤301 \le n \le 30, 1≤p≤1061 \le p \le 10^6.

For all testdata, 1≤n≤1001 \le n \le 100, 1≤p≤10181 \le p \le 10^{18}.

Translated by ChatGPT 5