FastPrepReach The Point

Reach The Point

Samsung logoSamsung● MediumOA
Learn

Problem statement

Suppose there is a grid consisting of an infinite number of cells and you are standing on cell (0,0).

Let your move strength be K which is initially set to 1.

In one move you can perform the following operations:

  • Move horizontally i.e. (x+k,y) from (x,y)
  • Move vertically i.e. (x,y+k) from (x,y)
  • Increase the value of K by 1

Find and print the minimum number of moves to reach the destination cell represented by (a,b).

Input

Each test contains multiple test cases. The first line contains the number of test cases t(1≤t≤10^3). Description of the test cases follows.

The first line and only line of each test case contain two-spaced integers a and b (1≤a,b≤10^9).

Output

Print the minimum moves for each test case in separate lines.

Function

minimumMoves(a: int, b: int) → int

Examples

Example 1

a = 1b = 6return = 5

For the first test case, First move to (1,0), then increase the value of K to 2, and then move three times to reach (1,6). Hence, it takes a total of 5.

Example 2

a = 1b = 1return = 2

:)

Constraints

  • 1 ≤ t ≤ 10^3 1 ≤ a, b ≤ 10^9

More Samsung problems

See Samsung hiring insights
public int minimumMoves(int a, int b) {
  // write your code here
}
a1
b6
expected5
Checking account…