310314: CF1814B. Long Legs

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Long Legstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A robot is placed in a cell $(0, 0)$ of an infinite grid. This robot has adjustable length legs. Initially, its legs have length $1$.

Let the robot currently be in the cell $(x, y)$ and have legs of length $m$. In one move, it can perform one of the following three actions:

  • jump into the cell $(x + m, y)$;
  • jump into the cell $(x, y + m)$;
  • increase the length of the legs by $1$, i. e. set it to $m + 1$.

What's the smallest number of moves robot has to make to reach a cell $(a, b)$?

Input

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.

The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the ending cell.

Output

For each test case, print a single integer — the smallest number of moves the robot is required to make to reach a cell $(a, b)$ from a cell $(0, 0)$.

ExampleInput
3
1 1
1 6
8 4
Output
2
5
6
Note

In the first testcase, the robot can first jump to $(0, 1)$, then to $(1, 1)$. If it ever increases the length of its legs, it will only be able to jump past $(1, 1)$.

In the second testcase, the robot can jump to $(1, 0)$, then increase the length of its length to $2$ and jump three times to reach $(1, 6)$.

In the third testcase, the robot can increase the length of its legs three times to make it $4$. Then jump to $(0, 4)$. Then jump twice to reach $(8, 4)$.

Input

题意翻译

给你一个无限大小的棋盘,一个机器人初始位置为 $(0,0)$,初始每次可移动的长度为 $1$。 对于一个当前在 $(x,y)$ 的机器人,且它当前的可移动长度为 $m$(初始为 $1$)。则它可以耗费一个时间进行如下操作: $\qquad$ 1.移动到 $(x+m,y)$。 $\qquad$ 2.移动到 $(x,y+m)$。 $\qquad$ 3.使得 $m=m+1$。 注意:在当前位置使得 $m=m+1$ 后会影响后面的操作。 现在给你两个正整数 $a,b(1 \leq a,b \leq 10^9)$,问机器人最少需要多少单位时间可以到达 $(a,b)$。

Output

题目大意:
一个机器人位于无限网格的单元格(0, 0)中,其腿长可调节,初始长度为1。机器人当前在单元格(x, y)中,腿长为m。在一步中,它可以执行以下三种动作之一:
1. 跳到单元格(x + m, y);
2. 跳到单元格(x, y + m);
3. 增加腿长1,即设置为m + 1。

问:机器人到达单元格(a, b)所需的最小移动次数是多少?

输入数据格式:
第一行包含一个整数t(1 ≤ t ≤ 100)——测试用例的数量。
每个测试用例的一行包含两个整数a和b(1 ≤ a, b ≤ 10^9)——结束单元格。

输出数据格式:
对于每个测试用例,打印一个整数——机器人从单元格(0, 0)到达单元格(a, b)所需的最小移动次数。题目大意: 一个机器人位于无限网格的单元格(0, 0)中,其腿长可调节,初始长度为1。机器人当前在单元格(x, y)中,腿长为m。在一步中,它可以执行以下三种动作之一: 1. 跳到单元格(x + m, y); 2. 跳到单元格(x, y + m); 3. 增加腿长1,即设置为m + 1。 问:机器人到达单元格(a, b)所需的最小移动次数是多少? 输入数据格式: 第一行包含一个整数t(1 ≤ t ≤ 100)——测试用例的数量。 每个测试用例的一行包含两个整数a和b(1 ≤ a, b ≤ 10^9)——结束单元格。 输出数据格式: 对于每个测试用例,打印一个整数——机器人从单元格(0, 0)到达单元格(a, b)所需的最小移动次数。

加入题单

算法标签: