#P15837. [蓝桥杯第一届国际赛] 希尔伯特曲线
[蓝桥杯第一届国际赛] 希尔伯特曲线
Problem Description
A Hilbert curve is a recursively defined curve. An -order Hilbert curve is defined on a 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 -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 , and the coordinates of the lower-right cell as . 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: . 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 , find the coordinates of the -th point that the -order Hilbert curve passes through.
Input Format
The input contains one line with two integers .
Output Format
Output one line with two integers separated by a single space, representing the required coordinates.
2 5
0 2
Hint
Constraints
For of the testdata, , .
For of the testdata, , .
For all testdata, , .
Translated by ChatGPT 5