AtCoder Grand Contest 061
A
Long Shuffle
AtCoder
⌀ 1643
原题
←B →
翻译中…

Problem Statement

翻译中…

There is an array $A_1, \ldots, A_N$, and initially $A_i = i$ for all $i$. Define the following routine $\mathrm{shuffle}(L, R)$:

翻译中…
  • If $R = L + 1$, swap values of $A_L$ and $A_R$ and terminate.
  • Otherwise, run $\mathrm{shuffle}(L, R - 1)$ followed by $\mathrm{shuffle}(L + 1, R)$.
翻译中…

Suppose we run $\mathrm{shuffle}(1, N)$. Print the value of $A_K$ after the routine finishes.

翻译中…

For each input file, solve $T$ test cases.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 1000$
  • $2 \leq N \leq 10^{18}$
  • $1 \leq K \leq N$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
case_1
case_2
\vdots
case_T

翻译中…

Each case is in the following format:

翻译中…

N K

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain the answer for the $i$-th case.

翻译中…

样例

Input #1
7
2 1
2 2
5 1
5 2
5 3
5 4
5 5
Output #1
2
1
2
4
1
5
3
For $N=2$, we do the following and get $A=(2,1)$. - Run $\mathrm{shuffle}(1, 2)$, and swap $A_1$ and $A_2$. For $N=5$, we do the following and get $A=(2,4,1,5,3)$. - Run $\mathrm{shuffle}(1, 5)$: - Run $\mathrm{shuffle}(1, 4)$: - Run $\mathrm{shuffle}(1, 3)$: - $\vdots$ - Run $\mathrm{shuffle}(2, 4)$: - $\vdots$ - Run $\mathrm{shuffle}(2, 5)$: - Run $\mathrm{shuffle}(2, 4)$: - $\vdots$ - Run $\mathrm{shuffle}(3, 5)$: - $\vdots$
题目信息
题号
agc061_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。