#P6232. [eJOI 2019] 挂架
[eJOI 2019] 挂架
Description
A hanging rack consists of layers of connecting rods. Layer () contains connecting rods. The midpoint of the rod in layer is fixed to the wall. In every other layer, the midpoint of the -th rod () is fixed to the -th rod in the previous layer. If is odd, it is fixed to the left endpoint of that rod; if is even, it is fixed to the right endpoint. On the bottom layer, each rod has a hook at both its left and right endpoints for hanging clothes. Each hook can hold at most one piece of clothing.
For example, when , the rack looks like this:

Mojca wants to hang all her clothes on this rack. Each piece of clothing weighs exactly one unit. To avoid breaking the rack’s fragile structure, she must hang the clothes one by one following a specific rule (i.e., in some order):
- After hanging one piece of clothing, for every connecting rod, let the total weight below its left endpoint be and below its right endpoint be . It must always hold that . Note that it must not be .
The rods and hooks are very light, so their weight can be ignored.
Mojca has heard that you are very capable, so she asks for your help. Given two integers , determine on which hook the -th piece of clothing should be hung.
Input Format
The input contains one line with two positive integers .
Output Format
Output one line with a single integer: the index of the hook on which the -th piece of clothing should be hung, taken modulo . The hook indices are not the same as the connecting rod indices.
3 2
5
5 10
19
Hint
Sample Input/Output Explanation
Sample 1 Explanation
- The order of using the hooks should be: . Therefore, the second piece of clothing should be hung on hook .
Sample 2 Explanation
- Here, the hooks are used in the order:
Constraints
This problem uses bundled subtasks, with a total of 3 subtasks.
- Subtask 1 (20 points): .
- Subtask 2 (20 points): .
- Subtask 3 (60 points): no special restrictions.
For all testdata, it is guaranteed that and .
Notes
The original problem is from: eJOI2019 Problem B. Hanging Rack
Translation provided by: @_Wallace_ (They felt that the LOJ translation was simplified too much and could cause ambiguity, so they translated it again.)
Translated by ChatGPT 5
京公网安备 11011102002149号