Problem:
 Score : 700 points    Problem Statement 10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}} -th.  The score of a participant is the product of his/her ranks in the two contests.  Process the following Q queries:   In the i -th query, you are given two positive integers A_i and B_i . Assuming that Takahashi was ranked A_i -th in the first contest and B_i -th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.       Constraints  1 \leq Q \leq 100  1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)  All values in input are integers.         Input Input is given from Standard Input in the following format:  Q  A_1  B_1  :  A_Q  B_Q       Output For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.        Sample Input 1 8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323      Sample Output 1 1
12
4
11
14
57
31
671644785  Let us denote a participant who was ranked x -th in the first contest and y -th in the second contest as (x,y) .  In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1 .

Solution (Python):
from math import sqrt
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    c = a * b
    d = int(sqrt(c))
    answer = 2 * d - 2
    if d**2 == c:
        answer -= 1
    if d * (d + 1) < c:
        answer += 1
    if a == b:
        answer += 1
    print(answer)

Solution (Python):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Solution (Python):
def d_worst_case(Q, R):
    import math
    ans = []
    for a, b in R:
        a, b = min(a, b), max(a, b)
        if a == b:
            ans.append(str(2 * a - 2))
        elif a + 1 == b:
            ans.append(str(2 * a - 2))
        else:
            c = int((a * b)**0.5)
            if c == (a * b)**0.5:
                c -= 1
            if c * (c + 1) >= a * b:
                ans.append(str(2 * c - 2))
            else:
                ans.append(str(2 * c - 1))
    return '\n'.join(ans)

Q = int(input())
R = [[int(i) for i in input().split()] for j in range(Q)]
print(d_worst_case(Q, R))

Solution (Python):

import math


def solve_worst(number_1, number_2):
    cases = 0
    if number_1 < number_2:
        number_1, number_2 = number_2, number_1

    if (number_1 * number_2) % (number_1 + 1) == 0:
        max_2 = number_1 * number_2 // (number_1 + 1) - 1
    else:
        max_2 = number_1 * number_2 // (number_1 + 1)
    cases += max_2

    min_sqrt = math.floor(math.sqrt(number_1 * number_2))
    if min_sqrt == number_2:
        min_sqrt = number_2 + 1
    cases += min_sqrt - number_2

    if (number_1 * number_2) % min_sqrt == 0:
        max_1 = number_1 * number_2 // min_sqrt - 2
    else:
        max_1 = number_1 * number_2 // min_sqrt - 1

    cases += max_1

    return cases


if __name__ == '__main__':
    Q = int(input())
    for i in range(Q):
        A, B = map(int, input().split())
        worst_cases = solve_worst(A, B)
        print(worst_cases)

Solution (Python):
Q = int(input())
for i in range(Q):
    a,b = (map(int, input().split()))
    if(a == b):
        print(2*a -2)
    elif(abs(a-b) == 1):
        print(2 * min(a,b) -2)
    else:
        c = int((a*b) ** 0.5)
        if c == (a*b) ** 0.5:
            c -= 1
        if(c*(c+1) >= a*b):
            print(2*c-2)
        else:
            print(2*c-1)

Solution (Python):
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b))
        if c == sqrt(a*b):
            c -= 1
        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)

Solution (Python):
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  buf = math.sqrt(q)
  buf = int(buf)
  if buf*buf == x[0]*x[1]:
    buf -= 1

  ans = buf * 2 - 2
  if buf*(buf+1) < x[0]*x[1]:
    ans += 1

  print ans

Solution (Python):
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1]:
    print 2*x[0] - 2
    continue

  if x[0]+1 == x[1]:
    print 2*x[0] - 2
    continue

  q = x[0]*x[1]
  q = int(math.sqrt(q))

  if q*q == x[0]*x[1]:
    q -= 1

  if q*(q+1) >= x[0]*x[1]:
    print 2*q - 2
    continue

  print 2*q - 1

Solution (Python):
from math import sqrt
q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    t = a*b
    s = int(sqrt(t))
    an = 2 * s - 2
    if s*s == t:
        an -= 1
    if s*(s+1) < t:
        an += 1
    if a == b:
        an += 1
    print(an)

Solution (Python):
import math
n = int(input())

for i in range(n):
    s, t = map(int, input().split())
    a = min(s, t)
    b = max(s, t)
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if x == q:
        x -= 1

    if a + 1 >= b:
        ans = a * 2 - 2
    elif x * (x + 1) >= a * b:
        ans = x * 2 - 2
    else:
        ans = x * 2 - 1
    print(ans)

Solution (Python):
Q = int(input())

def f(L):
    A, B = L
    N = 2 * (A * B) ** 0.5
    K = int(N)
    
    K -= 1 if K == N else 0
    
    res = K - 1
    if A + B == K:
        res -= 1
    else:
        
        if (K - 1 >= A or K - 1 >= B) and A != B:
            res -= 1
    return res
    
for _ in range(Q):
    q = list(map(int, input().split()))
    print(f(q))

Solution (Python):
import math
Q = int(input())
for _ in range(Q):
    A, B = list(map(int, input().split()))

    div = A * B
    ca = int(math.sqrt(div))
    if ca == A:
        ca += 1
    result = ca - 1
    if A <= ca:
        result -= 1
    cand = float("inf")
    while True:
        if ca == A:
            ca += 1
        cb = min(div // ca, cand)
        if cb * ca == div:
            cb -= 1
        if cb == B:
            cb -= 1
        if cb == cand:
            result += cb - 1
            if B <= cand:
                result -= 1
            break
        cand = cb
        result += 1
        
        ca += 1
        if cb == 1 or ca == 1:
            if B <= cand:
                result -= 1
            break
    print(result)

Solution (Python):
from math import sqrt

Q = int(input())

for i in range(Q):
    A, B = list(map(int, input().split()))

    sq = sqrt(A*B)
    sq_int = int(sq)

    ans = sq_int*2 - 2
    if sq_int**2==A*B and A!=B:
        ans -= 1
    if sq_int*(sq_int+1)<A*B:
        ans += 1

    
    print(ans)

Solution (Python):
import numpy as np
q = input()

n = np.zeros((q, 2), dtype=np.int64)
for i in range(0, q):    
    n[i, :] = map(int, raw_input().split())

for i in range(0, q):


    s = n[i, 0] * n[i, 1]
    m = int(np.floor(np.sqrt(s)))

    

    if n[i, 0] == n[i, 1]:        
        print m * 2 - 2
    elif m ** 2 == s:         
        print m * 2 - 3
    
    
    elif m ** 2 < s - m:         
        print m * 2 - 1
    else:
        print m * 2 - 2

Solution (Python):
import numpy as np

q = int(input())

for _ in range(q):
    a, b = sorted(list(map(int, input().split(' '))))
    n = int(np.floor(np.sqrt(a * b)))

    cnt = (n - 1) * 2

    if a != b:
        if a == n:
            if n * (n + 1) < a * b:
                cnt += 1
        else:
            cnt += 1
            if n ** 2 == a * b:
                cnt -= 1
            if n * (n + 1) >= a * b:
                cnt -= 1

    print(cnt)

Solution (Python):
import math

q = int(input())
a = []
for i in range(q):
    a.append(list(map(int, input().split())))
for i in range(q):
    b = max(2 * int(math.sqrt(a[i][0] * a[i][1])) - 3, 0)
    while True:
        status = True
        if b % 2 == 0:
            if (b // 2 + (a[i][0] <= b // 2)) * (b // 2 + 2 - (a[i][1] >= b//2 + 2)) < a[i][0] * a[i][1] and (b // 2 + 1 + (a[i][0] <= b // 2 + 1)) * (b // 2 + 1 - (a[i][1] >= b // 2 + 1)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
        else:
            if ((b - 1) // 2 + (a[i][0] <= (b - 1) // 2)) * ((b + 5) // 2 - (a[i][1] >= (b + 5) // 2)) < a[i][0] * a[i][1] and ((b + 1) // 2 + (a[i][0] <= (b + 1) // 2)) * ((b + 3) // 2 - (a[i][1] >= (b + 3) // 2)) < a[i][0] * a[i][1] and ((b + 3) // 2 + (a[i][0] <= (b + 3) // 2)) * ((b + 1) // 2 - (a[i][1] >= (b + 1) // 2)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
    print(b - 1)

Solution (Python):
import math
q = int(input())
a = [[int(i) for i in input().split()] for i in range(q)]
for i in a:
	if i[0]==i[1]: print((i[0]-1)*2)
	else:
		x = int(math.sqrt(i[0]*i[1]))
		if x*(x+1)<i[0]*i[1]: print(2*x-1)
		elif x==math.sqrt(i[0]*i[1]): print(2*x-3)
		else: print(2*x-2)