A11347 | Vlad and an Odd Ordering
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vladislav has $n$ cards numbered $1, 2, \dots, n$ . He wants to lay them down in a row as follows:
- First, he lays down all the odd-numbered cards from smallest to largest.
- Next, he lays down all cards that are twice an odd number from smallest to largest (i.e. $2$ multiplied by an odd number).
- Next, he lays down all cards that are $3$ times an odd number from smallest to largest (i.e. $3$ multiplied by an odd number).
- Next, he lays down all cards that are $4$ times an odd number from smallest to largest (i.e. $4$ multiplied by an odd number).
- And so on, until all cards are laid down.
What is the $k$ -th card he lays down in this process? Once Vladislav puts a card down, he cannot use that card again.
- First, he lays down all the odd-numbered cards from smallest to largest.
- Next, he lays down all cards that are twice an odd number from smallest to largest (i.e. $2$ multiplied by an odd number).
- Next, he lays down all cards that are $3$ times an odd number from smallest to largest (i.e. $3$ multiplied by an odd number).
- Next, he lays down all cards that are $4$ times an odd number from smallest to largest (i.e. $4$ multiplied by an odd number).
- And so on, until all cards are laid down.
What is the $k$ -th card he lays down in this process? Once Vladislav puts a card down, he cannot use that card again.
输入格式
The first line contains an integer $t$ ( $1 \leq t \leq 5 \cdot 10^4$ ) — the number of test cases.
The only line of each test case contains two integers $n$ and $k$ ( $1 \leq k \leq n \leq 10^9$ ) — the number of cards Vlad has, and the position of the card you need to output.
The only line of each test case contains two integers $n$ and $k$ ( $1 \leq k \leq n \leq 10^9$ ) — the number of cards Vlad has, and the position of the card you need to output.
输出格式
For each test case, output a single integer — the $k$ -th card Vladislav lays down.
输入输出样例
输入 #1
11 7 1 7 2 7 3 7 4 7 5 7 6 7 7 1 1 34 14 84 19 1000000000 1000000000
输出 #1
1 3 5 7 2 6 4 1 27 37 536870912
In the first seven test cases, $n=7$ . Vladislav lays down the cards as follows:
- First — all the odd-numbered cards in the order $1$ , $3$ , $5$ , $7$ .
- Next — all cards that are twice an odd number in the order $2$ , $6$ .
- Next, there are no remaining cards that are $3$ times an odd number. (Vladislav has only one of each card.)
- Next — all cards that are $4$ times an odd number, and there is only one such card: $4$ .
- There are no more cards left, so Vladislav stops.
Thus the order of cards is $1$ , $3$ , $5$ , $7$ , $2$ , $6$ , $4$ .
- First — all the odd-numbered cards in the order $1$ , $3$ , $5$ , $7$ .
- Next — all cards that are twice an odd number in the order $2$ , $6$ .
- Next, there are no remaining cards that are $3$ times an odd number. (Vladislav has only one of each card.)
- Next — all cards that are $4$ times an odd number, and there is only one such card: $4$ .
- There are no more cards left, so Vladislav stops.
Thus the order of cards is $1$ , $3$ , $5$ , $7$ , $2$ , $6$ , $4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted