FastPrepFastPrep
Problem Brief

Reach The Point

OA

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.

    1Example 1

    Input
    a = 1, b = 6
    Output
    5
    Explanation
    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.

    2Example 2

    Input
    a = 1, b = 1
    Output
    2
    Explanation
    :)

    Constraints

    Limits and guarantees your solution can rely on.

    1 ≤ t ≤ 10^3
    1 ≤ a, b ≤ 10^9
    public int minimumMoves(int a, int b) {
      // write your code here
    }
    
    Input

    a

    1

    b

    6

    Output

    5

    Sign in to submit your solution.