CF2184C.Huge Pile

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Andrei has a huge pile of nn apples. He can divide the pile into two smaller piles: if there are xx apples in the pile, he will get piles with ⌊x2⌋\lfloor \frac{x}{2} \rfloor∗^{\text{∗}} and ⌈x2⌉\lceil \frac{x}{2} \rceil†^{\text{†}} apples. This division takes Andrei 11 minute.

Andrei wants to eat kk apples, but he doesn't want to count them at all. That is why he wants to obtain a pile that contains exactly kk apples. Determine whether it is possible to achieve this by performing pile divisions. If it is possible, find the minimum possible time for Andrei to obtain a pile with exactly kk apples.

∗^{\text{∗}}⌊x2⌋\lfloor \frac{x}{2} \rfloor — the largest integer ≤x2\le \frac{x}{2}.

†^{\text{†}}⌈x2⌉\lceil \frac{x}{2} \rceil — the smallest integer ≥x2\ge \frac{x}{2}.

安德烈有一大堆 nn 个苹果。他可以将一堆苹果分成两堆更小的苹果堆:若当前堆中有 xx 个苹果,则分出的两堆分别含有 ⌊x2⌋\lfloor \frac{x}{2} \rfloor∗^{\text{∗}} 和 ⌈x2⌉\lceil \frac{x}{2} \rceil†^{\text{†}} 个苹果。每次分堆操作耗时 11 分钟。

安德烈想吃掉 kk 个苹果,但他完全不想手动计数。因此,他希望得到一堆恰好含有 kk 个苹果的苹果堆。请判断是否能通过若干次分堆操作达成这一目标;若可以,请找出安德烈获得一堆恰好 kk 个苹果所需的最短时间。

∗^{\text{∗}}⌊x2⌋\lfloor \frac{x}{2} \rfloor —— 表示不超过 x2\frac{x}{2} 的最大整数。

†^{\text{†}}⌈x2⌉\lceil \frac{x}{2} \rceil —— 表示不小于 x2\frac{x}{2} 的最小整数。

输入格式

Each test consists of several test cases. The first line contains a single integer tt (1≤t≤104)(1 \le t \le 10^4) — the number of test cases. The following lines describe the test cases.

In the only line of each test case, two integers nn and kk are given — the number of apples in the huge pile and the number of apples that Andrei wants to obtain in one pile (1≤n,k≤109)(1 \le n, k \le 10^9).

每个测试包含若干测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。接下来的行描述各个测试用例。

在每个测试用例的唯一一行中,给出两个整数 nn 和 kk —— 分别表示大堆中的苹果数量以及 Andrei 希望在一堆中获得的苹果数量(1≤n,k≤1091 \le n, k \le 10^9)。

输出格式

For each test case, output −1-1 if it is impossible to obtain a pile with exactly kk apples. Otherwise, output the minimum possible time required to obtain such a pile.

对于每个测试用例,如果无法得到恰好包含 kk 个苹果的堆,则输出 −1-1;否则,输出得到这样一堆苹果所需的最少时间。

输入输出样例

  • 输入#1

    4
    10 3
    11 5
    21 4
    1000000000 1

    输出#1

    2
    1
    -1
    29

说明/提示

In the first test case, after the first division, two piles of 55 apples will be created. If one of them is divided, it will result in piles with 22 and 33 apples, so the answer is 22.

In the second test case, if the pile is divided into two, it will result in piles with 55 and 66 apples, so the answer is 11.

In the third test case, it is only possible to obtain piles with 11, 22, 33, 55, 66, 1010, 1111, or 2121 apples, so the answer is −1-1.

在第一个测试用例中,第一次分割后会得到两堆苹果,每堆各有 55 个。若再将其中一堆分割,则会产生分别含 22 个和 33 个苹果的两堆,因此答案为 22。

在第二个测试用例中,若将原堆分割为两堆,则会得到分别含 55 个和 66 个苹果的两堆,因此答案为 11。

在第三个测试用例中,仅可能得到含 11、22、33、55、66、1010、1111 或 2121 个苹果的堆,因此答案为 −1-1。

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

首页