CF2182B.New Year Cake

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Monocarp is going to bake a New Year cake.

The cake must consist of at least one layer. The size of the top layer of the cake must be 11; the size of the layer below it must be 22; the layer below that must be 44, and so on (each layer, except for the top one, is twice the size of the layer above it).

Additionally, each layer must be covered with either white or dark chocolate. To cover a layer of size kk, Monocarp will need kk kilograms of chocolate. Each layer must be covered with exactly one type of chocolate, and these types must alternate (if some layer is covered with dark chocolate, both the layer directly below it and the layer directly above it must be covered with white chocolate, and vice versa).

Monocarp has aa kilograms of white chocolate and bb kilograms of dark chocolate. He wants to calculate the maximum number of layers that the cake can consist of, ensuring that he has enough chocolate of both types.

Monocarp 打算烘烤一个新年蛋糕。

蛋糕必须至少包含一层。蛋糕最顶层的尺寸必须为 11;其正下方一层的尺寸必须为 22;再下一层的尺寸必须为 44,依此类推(除最顶层外,每一层的尺寸均为其上方一层的两倍)。

此外,每一层必须用白色巧克力或深色巧克力中的一种覆盖。覆盖尺寸为 kk 的一层需要 kk 千克巧克力。每一层必须恰好使用一种巧克力,并且相邻层所用巧克力类型必须交替(即:若某一层使用深色巧克力,则其正上方和正下方的层都必须使用白色巧克力;反之亦然)。

Monocarp 拥有 aa 千克白色巧克力和 bb 千克深色巧克力。他希望计算出蛋糕最多能有多少层,同时确保两种巧克力的用量均不超过其现有库存。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of one line containing two integers aa and bb (1≤a,b≤1061 \le a, b \le 10^6).

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

每个测试用例由一行组成,该行包含两个整数 aa 和 bb(1≤a,b≤1061 \le a, b \le 10^6)。

输出格式

For each test case, output one integer — the maximum possible number of layers in the cake.

对于每个测试用例,输出一个整数——蛋糕可能的最大层数。

输入输出样例

  • 输入#1

    7
    1 1
    1 2
    3 1
    4 3
    5 2
    1000000 1000000
    1000000 1

    输出#1

    1
    2
    2
    2
    3
    20
    2

说明/提示

In the first example, Monocarp can bake a cake with one layer of size 11 and cover it with any type of chocolate.

In the second example, Monocarp can bake a cake with two layers: the top layer of size 11 with white chocolate, and below it a layer of size 22 with dark chocolate.

In the third example, Monocarp can bake a cake with two layers: the top layer of size 11 with dark chocolate, and below it a layer of size 22 with white chocolate.

In the fourth example, Monocarp can bake a cake with two layers: the top layer of size 11 with dark chocolate, and below it a layer of size 22 with white chocolate. Note that a cake with three layers, where the top layer of size 11 and the layer below it of size 22 are both dark chocolate, and the bottom layer of size 44 is white chocolate, is not valid, as the types of layers must alternate.

在第一个例子中,Monocarp 可以烘焙一个仅含一层、尺寸为 11 的蛋糕,并用任意一种巧克力覆盖它。

在第二个例子中,Monocarp 可以烘焙一个含两层的蛋糕:顶层尺寸为 11,使用白巧克力;其下方一层尺寸为 22,使用黑巧克力。

在第三个例子中,Monocarp 可以烘焙一个含两层的蛋糕:顶层尺寸为 11,使用黑巧克力;其下方一层尺寸为 22,使用白巧克力。

在第四个例子中,Monocarp 可以烘焙一个含两层的蛋糕:顶层尺寸为 11,使用黑巧克力;其下方一层尺寸为 22,使用白巧克力。注意:一个含三层的蛋糕(顶层尺寸为 11、其下一层尺寸为 22,均使用黑巧克力,底层尺寸为 44 使用白巧克力)是不合法的,因为各层的巧克力类型必须交替出现。

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

首页