CF1926E.Vlad and an Odd Ordering

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vladislav has nn cards numbered 1,2,…,n1, 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. 22 multiplied by an odd number).
  • Next, he lays down all cards that are 33 times an odd number from smallest to largest (i.e. 33 multiplied by an odd number).
  • Next, he lays down all cards that are 44 times an odd number from smallest to largest (i.e. 44 multiplied by an odd number).
  • And so on, until all cards are laid down.

What is the kk-th card he lays down in this process? Once Vladislav puts a card down, he cannot use that card again.

弗拉迪斯拉夫有 nn 张编号为 1,2,…,n1, 2, \dots, n 的卡片。他希望按如下方式将这些卡片排成一行:

  • 首先,他按从小到大的顺序放置所有奇数编号的卡片;
  • 接着,他按从小到大的顺序放置所有形如“2 乘以一个奇数”的卡片(即能被 2 整除但不能被 4 整除的数);
  • 接着,他按从小到大的顺序放置所有形如“3 乘以一个奇数”的卡片(即能被 3 整除但不能被 6 整除的数?注意:此处应严格按题意理解为 3×odd3 \times \text{odd},即所有可表示为 33 乘以某个奇数的数,例如 3,9,15,…3,9,15,\dots,但需满足 ≤n\le n);
  • 接着,他按从小到大的顺序放置所有形如“4 乘以一个奇数”的卡片(即 4×odd4 \times \text{odd});
  • 如此继续下去,直到所有卡片都被放置完毕。

在此过程中,他放置的第 kk 张卡片是什么?一旦弗拉迪斯拉夫放置了一张卡片,他就不能再重复使用该卡片。

输入格式

The first line contains an integer tt (1≤t≤5⋅1041 \leq t \leq 5 \cdot 10^4) — the number of test cases.

The only line of each test case contains two integers nn and kk (1≤k≤n≤1091 \leq k \leq n \leq 10^9) — the number of cards Vlad has, and the position of the card you need to output.

第一行包含一个整数 tt(1≤t≤5⋅1041 \leq t \leq 5 \cdot 10^4)—— 测试用例的数量。

每个测试用例仅有一行,包含两个整数 nn 和 kk(1≤k≤n≤1091 \leq k \leq n \leq 10^9)—— 分别表示弗拉德拥有的卡片数量,以及你需要输出的卡片的位置。

输出格式

For each test case, output a single integer — the kk-th card Vladislav lays down.

对于每个测试用例,输出一个整数——即弗拉迪斯拉夫放置的第 kk 张卡片。

输入输出样例

  • 输入#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=7n=7. Vladislav lays down the cards as follows:

  • First — all the odd-numbered cards in the order 11, 33, 55, 77.
  • Next — all cards that are twice an odd number in the order 22, 66.
  • Next, there are no remaining cards that are 33 times an odd number. (Vladislav has only one of each card.)
  • Next — all cards that are 44 times an odd number, and there is only one such card: 44.
  • There are no more cards left, so Vladislav stops.

Thus the order of cards is 11, 33, 55, 77, 22, 66, 44.

在前七个测试用例中,n=7n=7。弗拉迪斯拉夫按如下方式摆放卡片:

  • 首先——所有奇数编号的卡片,按顺序 11、33、55、77 排列;
  • 接着——所有形如“偶数 = 奇数 × 2”的卡片,按顺序 22、66 排列;
  • 接着——不存在剩余的形如“偶数 = 奇数 × 3”的卡片(弗拉迪斯拉夫每种卡片仅有一张);
  • 接着——所有形如“偶数 = 奇数 × 4”的卡片,其中仅有一张:44;
  • 此时已无剩余卡片,因此弗拉迪斯拉夫停止操作。

因此卡片的排列顺序为 11、33、55、77、22、66、44。

输入解题思路,AI测评打分。不知道怎么写?

首页