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):

q=int(input())
C=[]
for i in range(q):
    C.append(list(map(int, input().split())))
for i in C:
    k=min(i[0],i[1])
    score=i[0]*i[1]
    sqrt=int(score**0.5)
    if abs(i[0]-i[1])<=1:
        ans=(k-1)*2
    elif sqrt**2==score:
        ans=sqrt*2-3
    elif sqrt*(sqrt+1)>=score:
        ans=(sqrt-1)*2
    else:
        ans=sqrt*2-1
    print(ans)

Solution (Python):
import math

Q = int(input())

D = []
for i in range(Q):
  D.append(list(map(int, input().split())))
           
for i in D:
  t = i[0] * i[1]
  l = int(t**0.5)
  if i[0] == i[1]:
    Ans = (l - 1) * 2
  elif l * l == t:
    Ans = (l - 1) * 2 - 1
  elif l * (l + 1) >= t:
    Ans = (l - 1) * 2
  else:
    Ans = l * 2 - 1
  print(Ans)

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

def solve(a,b):
    if a == b:
        return 2*a-2
    if b < a:
        return solve(b, a)

    lb, ub, ab = a, 2*b, a*b
    while ub-lb > 1:
        mid = (lb+ub)//2
        """
        1<= k <= xとした時の
        k(x+1-k)の最大値を取るのはk = (x+1)//2の時
        !!!k(x-k)ではない!!!
        これだとk=xで0になってしまう
        """
        maxp = (mid+1)//2*(mid+1-(mid+1)//2)
        if maxp < ab:
            lb = mid
        else:
            ub = mid
    
    return lb-1

for _ in range(q):
    a, b = map(int, input().split())
    t = solve(a,b)
    print(t)

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

def solve(a,b):
    if a == b:
        return 2*a-2
    if b < a:
        return solve(b, a)

    lb, ub, ab = a, 2*b, a*b
    while ub-lb > 1:
        mid = (lb+ub)//2
        maxp = (mid)//2*(mid-(mid)//2)
        if maxp < ab:
            lb = mid
        else:
            ub = mid
    return lb-2

for _ in range(q):
    a, b = map(int, input().split())
    t = solve(a,b)
    print(t)

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

def solve(a,b):
    if a == b:
        return 2*a-2
    if b < a:
        return solve(b, a)

    lb, ub, ab = a, 2*b, a*b
    while ub-lb > 1:
        mid = (lb+ub)//2
        maxp = (mid+1)//2*(mid+1-(mid+1)//2)
        if maxp < ab:
            lb = mid
        else:
            ub = mid
    return lb-1

for _ in range(q):
    a, b = map(int, input().split())
    print(solve(a,b))

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


def solve(a, b):
    if a == b:
        return 2 * a - 2
    if b < a:
        return solve(b, a)
    lb, ub, ab = a, 2 * b, a * b
    while 1 < ub - lb:
        mid = (lb + ub) // 2
        maxp = (mid + 1) // 2 * (mid // 2 + 1)
        if maxp < ab:
            lb = mid
        else:
            ub = mid
    return lb - 1

for _ in range(Q):
    a, b = map(int, input().split())
    print(solve(a, b))

Solution (Python):

import math

def main():
    Q = int(input())
    A = []
    B = []
    for i in range(Q):
        na = list(map(int, input().split()))
        A.append(na[0])
        B.append(na[1])

    for i in range(Q):
        a, b = A[i], B[i]

        if a == b:
            print(a * 2 - 2)
            continue

        c = a * b
        d = int(math.sqrt(c))
        if d * (d + 1) < c:
            print(d * 2 - 1)
        elif d ** 2 == c:
            print(d * 2 - 3)
        else:
            print(d * 2 - 2)


if __name__ == '__main__':
    main()

Solution (Python):
Q = int(input())
for q in range(Q):
    A, B = map(int, input().split())
    A, B = min(A, B), max(A, B)
    
    
    if A == B:
        print(2 * (A - 1))
        continue

    
    ok, ng = 0, A + B - 1
    while abs(ok - ng) > 1:
        K = (ok + ng) // 2
        m = (K + 2) // 2

        if m * (K + 2 - m) < A * B:
            ok = K
        else:
            ng = K

    print(ok)

Solution (Python):


Q = int(input())
for q in range(Q):
    A, B = map(int, input().split())
    A, B = min(A, B), max(A, B)

    ok, ng = 0, 10 ** 9 + 1
    while abs(ok - ng) > 1:
        K = (ok + ng) // 2
        m = (A + K) // 2

        
        if K == A:
            m -= 1

        if m * (A + K - m) < A * B:
            ok = K
        else:
            ng = K

    print(A + ok - 2)

Solution (Python):
import math
def near_sqrt(a,b):
  c = a * b
  d = math.floor(math.sqrt(c))
  if d*(d+1) < c:
    return d
  else:
    return (d-1)
  
q = int(input())
for i in range(q):
  a,b = map(int, input().split())
  c = near_sqrt(a,b)
  d = (a*b)%(c+1)
  if d == 0 and a!=b:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)

Solution (Python):
import math
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  sqrt = int(math.sqrt(a * b))
  sqrt2 = sqrt + 1 if sqrt * (sqrt + 1) < a * b else sqrt
  sub = 1 if sqrt == max(a, b) or sqrt2 == min(a, b) or sqrt * sqrt2 == a * b else 0
  add = min(max(sqrt2 - min(a, b) - 1, 0), max(max(a, b) - sqrt - 1, 0))
  print(min(a, b) - 1 + sqrt + add - sub)

Solution (Python):
import math

q = int(input())
s = []
for i in range(q):
    s.append([int(m) for m in input().split()])

def doublecount(dc, i):
    if dc >= s[i][0] and dc >= s[i][1]:
        return -2
    elif dc >= s[i][0] or dc >= s[i][1]:
        return -1
    else:
        return 0


count = 0
for i in range(q):
    t = int(math.sqrt(s[i][0] * s[i][1]))
    if t * (t + 1) < s[i][0] * s[i][1]:
        count = t * 2
        count += doublecount(t, i)
        print(count)
    else:
        if t * t < s[i][0] * s[i][1]:
            count = t * 2 - 1
            count += doublecount(t, i)
            print(count)
        else:
            count = (t - 1) * 2
            count += doublecount(t - 1, i)
            print(count)

Solution (Python):
import math

Q=int(input())
AB=[sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x=math.sqrt(A*B)
    y=int(x)
    if x!=y:
        y=int(x)
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from math import sqrt

def wc(a:int, b:int) -> int:
    
    if a == b:
        return 2*a - 2
    
    elif abs(a-b) == 1:
        return 2*min(a,b) - 2
    
    else:
        c = int(sqrt(a*b))
        if a*b == c*c:
            c -= 1
        
        if a*b > c*(c+1):
            return 2*c - 1
        else:
            return 2*c - 2
    

q = ni()
query = [tuple(li()) for _ in range(q)]

for a,b in query:
    print(wc(a,b))

Solution (Python):
Q = int(input())
AB = [list(map(int,input().split())) for _ in range(Q)]

def cn(A,B):
    score = A*B-1
    L = A+1
    R = score
    if L>R:
        return 0
    while L!=R:
        tmp = (L+R)//2
        if score > tmp*(tmp+1):
            L = tmp+1
        else:
            R = tmp
    return (L-1-A+score//L)
for ab in AB:
    print(cn(ab[0],ab[1])+cn(ab[1],ab[0]))

Solution (Python):
import math
q = int(input())
ab = [list(map(int, input().split())) for _ in range(q)]

for a, b in ab:
    a, b = min(a, b), max(a, b)
    p = a*b
    n = math.ceil((-1+(1+4*p)**(1/2))/2)
    if a <= n:
        lower1 = a-1

    if b <= n:
        lower2 = b-1
    else:
        m = p//n if p%n > 0 else p//n-1
        n_lim = p//(a+1) if p%(a+1) > 0 else p//(a+1)-1
        if n > n_lim:
            lower2 = n_lim
        else:
            lower2 = n + m - (a+1)
            
    print(lower1+lower2)

Solution (Python):
Q = int( input())
def matching(A,B):
    
    
    
    
    if A == B:
        return 2*A - 2
    S = A*B
    L, H = 0, A*B
    while H - L != 1:
        M = (L+H)//2
        if ((M+1)//2)*(M + 1 - (M+1)//2) < S:
            L = M
        else:
            H = M
    return L-1 
for _ in range(Q):
    A, B = map( int, input().split())
    print( matching(A,B))

Solution (Python):

q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    c=int((a*b)**0.5)
    if c*(c+1)<a*b: print(2*c-1)
    elif a*b==c*c and a!=b: print(2*c-3)
    else: print(2*c-2)

Solution (Python):
def min_square(min_,max_,AB):
    mid=(min_+max_)//2
    if max_-min_<=1:
        if mid**2<AB:
            return mid
        else:
            return mid-1
    if mid**2 < AB:
        return min_square(mid,max_,AB)
    elif mid**2>AB:
        return min_square(min_,mid,AB)
    else:
        return mid-1

Q=int(input())
for i in range(Q):
    AB=list(map(int,input().split()))
    if AB[0]==AB[1]:
        print((AB[0]-1)*2)
        continue
    mid = min_square(min(AB),max(AB),AB[0]*AB[1])
    if mid*(mid+1)<AB[0]*AB[1]:
        print(mid*2-1)
    else:
        print(mid*2-2)

Solution (Python):
def calc_max(a, b, n):
    if n == 0:
        return 0
    m = (b - a) // 2
    if m < 0:
        return a*b
    elif m < n:
        return (a+m)*(b-m)
    else:
        return (a+(n-1))*(b-(n-1))


def judge(a, b, m, x):
    max_value = 0
    if x == 0:
        pass
    elif x < a and x < b:
        max_value = calc_max(1, x, x)
    elif x >= a and x < b:
        max_value = max(calc_max(1, x, a-1),
                        calc_max(a+1, x-(a-1), x-(a-1)))
    else:
        max_value = max(calc_max(1, x+1, x+1-b),
                        calc_max(x + 1-b+1, b-1, a-(x+1-b+1)),
                        calc_max(a+1, x+1-a, x+1-a))
    return True if max_value < m else False


def bs(a, b):
    m = a * b
    lft = 0
    rgt = m
    nxt, prv = -1, -1
    while True:
        nxt = (lft + rgt) // 2
        if nxt == prv:
            return nxt
        if judge(a, b, m, nxt):
            lft = nxt
        else:
            rgt = nxt
        prv = nxt


Q = int(input())
for _ in range(Q):
    A, B = map(int, input().split())
    if A > B:
        A, B = B, A
    print(bs(A, B))

Solution (Python):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    a,b = map(int, sdin().split())
    if a > b:
        a,b = b,a
    ab.append(tuple([a,b]))

for a, b in ab:
    if  b-a < 2:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Solution (Python):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a >= 0 and b-a < 2:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Solution (Python):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a >= 0 and b-a <= 1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Solution (Python):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a == 0 or b-a == 1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Solution (Python):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Solution (Python):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Solution (Python):
from math import floor, sqrt
Q = int(input())
A = []

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

for i in range(Q):
  P,Q = min(A[i][0], A[i][1]), max(A[i][0], A[i][1])
  if P == Q or P == Q-1:
    print(2*(P - 1))
  else:
    C = floor(sqrt(P*Q))
    if C == sqrt(P*Q):
      C -= 1

    if C*(C+1) >= P*Q:
      print(2*C - 2)
    else:
      print(2*C - 1)

Solution (Python):
def f(a,b):
  if a>b:a,b=b,a
  if a==b or a+1==b:
    return 2*a-2
  else:
    c=int((a*b)**(1/2))
    if c**2==a*b:c-=1
    if c*(c+1)>=a*b:
      return 2*c-2
    else:
      return 2*c-1

q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  print(f(a,b))

Solution (Python):
from math import sqrt

q = int(input())

p = []
for _ in range(q):
    p.append(list(map(int, input().split())))

for t in p:
    x = min(t)
    y = max(t)
    if x == y or x + 1 == y:
        print(x * 2 - 2)
    else:
        temp = sqrt(x * y)
        hoge = int(temp)
        if hoge == temp:
            hoge -= 1
        if hoge * (hoge + 1) >= x * y:
            print(2 * hoge - 2)
        else:
            print(2 * hoge - 1)

Solution (Python):
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))

    if score[i][0]==score[i][1]:
        print(2*max_num-2)
    elif score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    else:
        print(2*max_num-2)

Solution (Python):
q = int(input())
ab = [tuple(map(int, input().split())) for _ in range(q)]



for a, b in ab:
    if a > b:
        large = a
        small = b
    elif a < b:
        large = b
        small = a
    else:
        print(2* a - 2)
        continue


    
    low_x = 0 
    upper_x = large - small + 1

    while upper_x- low_x> 1:
        mid_x = (low_x + upper_x ) //2

        
        is_ok = True
        for i in range(mid_x // 2 -2, mid_x //2 +3) :
            if i< 0 and b -a < i:
                continue
            if (small + i) * (small + mid_x - i) >= large* small:
                is_ok = False
                break

        if is_ok:
            low_x = mid_x
            x = mid_x
        else:
            upper_x = mid_x
            x= mid_x


    print(2 * small -2  + low_x)

Solution (Python):
from itertools import count, takewhile
from math import floor, sqrt

n = int(input())
xys = [map(int, input().split()) for _ in range(n)]

def mysqrt(n):
    x = floor(sqrt(n))
    for x in takewhile(lambda x: x**2 <= n, count(max(0, x-2))):
        pass
    return x

for x, y in xys:
    xy = x*y
    root = mysqrt(xy-1)
    ans = root*2 - (root**2 + root >= xy) - 1 + (x == y)
    print(ans)

Solution (Python):
from itertools import count, takewhile
from math import floor, sqrt
 
n = int(input())
xys = [map(int, input().split()) for _ in range(n)]
 
def mysqrt(n):
    x = floor(sqrt(n))
    for y in takewhile(lambda y: y**2 <= n, count(max(0, x-2))):
        x = y
    return x
 
for x, y in xys:
    xy = x*y
    root = mysqrt(xy-1)
    ans = root*2 - (root**2 + root >= xy) - 1 + (x == y)
    print(ans)

Solution (Python):
from itertools import count, takewhile
from math import floor, sqrt

n = int(input())
xys = [map(int, input().split()) for _ in range(n)]

def mysqrt(n):
    x = floor(sqrt(n))
    for y in takewhile(lambda y: y**2 <= n, count(max(0, x-10))):
        x = y
    return x

for x, y in xys:
    xy = x*y
    root = mysqrt(xy-1)
    ans = root*2 - (root**2 + root >= xy) - 1 + (x == y)
    print(ans)

Solution (Python):
from math import floor, sqrt
from itertools import count, takewhile

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n)]

def mysqrt(n):
    x = floor(sqrt(n))
    for y in takewhile(lambda y: y**2 <= n, count(max(0, x-10))):
        x = y
    return x

for xy in xys:
    a, b = sorted(xy)
    if b - a < 2:
        print(2*a - 2)
    else:
        ab = a*b
        c = mysqrt(ab-1)
        if c*(c+1) >= ab:
            print(c*2 - 2)
        else:
            print(c*2 - 1)

Solution (Python):
q = int(input())
ab = [tuple(map(int, input().split())) for _ in range(q)]



for a, b in ab:
    if a > b:
        large = a
        small = b
    elif a < b:
        large = b
        small = a
    else:
        print(2* a - 2)
        continue


    
    low_x = 0 
    upper_x = large - small + 1

    while upper_x- low_x> 1:
        mid_x = (low_x + upper_x ) //2

        
        is_ok = True
        for i in range(mid_x // 2 -2, mid_x //2 +3) :
            if i< 0 and b -a < i:
                continue
            if (small + i) * (small + mid_x - i) >= large* small:
                is_ok = False
                break

        if is_ok:
            low_x = mid_x
            x = mid_x
        else:
            upper_x = mid_x
            x= mid_x


    print(2 * small -2  + low_x)

Solution (Python):
import numpy as np

def solve(a, b):
    if a == b: return 2 * (a-1)
    scoreT = a*b
    x = y = int(np.sqrt(scoreT)) - 2
    while True:
        if (x+1)*y < scoreT:
            x += 1
        else:
            break
        if x*(y+1) < scoreT:
            y += 1
        else:
            break
    if x == y:
        return (x-1) * 2
    else:
        return y * 2 - 1


for i in range(int(input())):
    a, b = map(int, input().split())
    print(solve(a, b))

Solution (Python):
import math
Q = int(input())
for i in range(Q):
    a = list(map(int,input().split()))
    a.sort()
    A = a[0]
    B = a[1]
    n = 0
    if A==B:
        n = 2*A-2
    elif B == A+1:
        n = 2*A-2
    else:
        C = math.ceil(math.sqrt(A*B)-1)
        if C*(C+1)>=A*B:
            n = 2*C-2
        else:
            n = 2*C-1
    print(n)

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

for i in range(n):
  a,b=[int(i) for i in input().split()]
  if a==b:
    print((min(a,b)-1)*2)
  else:
    if int((a*b)**0.5) * (int((a*b)**0.5)+1) < a*b:
      print(int((a*b)**0.5) *2 - 1)
    elif int((a*b)**0.5) **2 == a*b:
      print(int((a*b)**0.5) *2 - 3)
    else:
      print(int((a*b)**0.5) *2 -2)

Solution (Python):
Q = int(input())
ab = [tuple(map(int, input().split())) for _ in range(Q)]

for a, b in ab:
    if a > b:
        tmp = a
        a = b
        b = tmp
    elif a == b:
        print(2 * a - 2)
        continue

    ans = 2 * a - 2

    
    x = 0
    low_x = 0
    upper_x = b - a + 1
    while upper_x - low_x > 1:
        mid_x = (low_x + upper_x) // 2

        
        flg = 1
        for j in range(mid_x//2-2,  mid_x//2+2 + 1):
            if j < 0 and b - a < j:
                continue
            if (a + j) * (a + mid_x - j) >= a * b:
                flg = 0
                break
        
        
        
        
        
        
        
        if flg:
            low_x = mid_x
            x = mid_x
        else:
            upper_x = mid_x
            x = mid_x

    print(ans + low_x)

Solution (Python):
from math import floor, sqrt

Q = int(input())
for q in range(Q):
  a, b = map(int, input().split())
  K = floor(sqrt(a*b))
  if a== b:
    print(2*K-2)
  elif a*b == K*K:
    print(2*K-3)
  elif K*(K+1) < a*b:
    print(2*K-1)
  else:
    print(2*K-2)

Solution (Python):
Q = int(input())
ans = []
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    if M*(M + 1) < A*B: 
        ans.append(2*M - 1)
    elif A*B == M*M and A != B: 
        ans.append(2*M - 3)
    else: 
        ans.append(2*M - 2)

print("\n".join(map(str, ans)))

Solution (Python):
import math

def worst_case(A, B):
    c = min(A, B)
    d = max(A, B)
    if c == d or c + 1 == d:
        return 2 * (c - 1)
    root = int(math.sqrt(A * B))
    if root ** 2 == A * B:
        root -= 1
    return 2 * (root - 1) + 1 if root * (root + 1) < A * B else 2 * (root - 1)

Q = int(input())
A = []
B = []
for i in range(Q):
    line = input().split()
    A.append(int(line[0]))
    B.append(int(line[1]))

for i in range(Q):
    print(worst_case(A[i], B[i]))

Solution (Python):
import sys

def kth(ed, erase, k):
  if (k < erase):
    return k
  return k + 1

def ck(a, b, x):
  c = x
  if a <= x:
    c += 1
  d = x
  if b <= x:
    d += 1
  if x % 2 == 1:
    m = (x + 1) / 2
    return kth(c, a, m) * kth(d, b, m) < a * b
  else:
    m0 = x / 2
    m1 = x / 2 + 1
    return kth(c, a, m0) * kth(d, b, m1) < a * b and kth(c, a, m1) * kth(d, b, m0) < a * b

T = int(raw_input())
while T > 0:
  a, b = map(int, raw_input().split())
  l = 0
  r = a * b
  while r - l > 1:
    m = (l + r) / 2
    if ck(a, b, m):
      l = m
    else:
      r = m
  if ck(a, b, r):
    print r
  else:
    print l
  T -= 1

Solution (Python):

Q = int(input())
for _ in range(Q):
    a, b = sorted([int(s) for s in input().split()])
    c_max = int((a * b) ** 0.5)
    if c_max * c_max == a * b:
        c_max -= 1
    sol = 2 * c_max
    if a <= c_max:
        sol -= 1
    if (c_max * c_max < a * b) and (c_max * (c_max + 1) >= a * b):
        sol -= 1
    print(sol)

Solution (Python):
from math import sqrt
from math import floor

Q = int(input())
A_list = []
B_list = []

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

for A, B in zip(A_list, B_list):
    if A == B:
        print(2*A-2)
        continue
    if abs( A - B) == 1:
        print(2*min(A, B)-2)
        continue
    C = int(floor(sqrt(A*B)))
    if C*C >= A*B:
        C -= 1
    if C * (C + 1) >= A*B:
        print(2*C-2)
        continue
    print(2*C-1)

Solution (Python):
import math

def solve(a, b):
	if a>b: a,b = b,a
	if a==b or a+1==b:
		return 2*a-2
	
	mul = a*b
	c = int(math.sqrt(mul))
	if c**2==mul: c-=1
	if c*(c+1)<mul:
		return 2*c-1 
	else:
		return 2*c-2 

n = int(input())
for _ in range(n):
	a,b = map(int, input().split())
	print(solve(a,b))

Solution (Python):
def solve(a,b):
  if a==b:
    return (a-1)+(b-1)
  elif a+1==b or b+1==a:
    return (min(a,b)-1)*2
  else:
    cnt=(a*b)**(1/2)
    if cnt==int(cnt):
      cnt=int(cnt)-1
    else:
      cnt=int(cnt)
    if cnt*(cnt+1)>=a*b:
      return int(cnt)*2-2
    else:
      return int(cnt)*2-1

Q=int(input())

for i in range(Q):
  a,b=map(int,input().split())
  print(solve(a,b))

Solution (Python):

import math

q=int(raw_input())
res=[]
for i in xrange(q):
 a,b=map(int,raw_input().split())
 m=a*b
 x=int(math.sqrt(m-1))
 while x**2>=m:
  x-=1
 y=x*2
 if x*(x+1)>=m:
  y-=1
 if max(a,b)<=x:
  res-=1
 if min(a,b)<=x:
  y-=1
 res.append(y)
for i in xrange(q):
 print res[i]

Solution (Python):
import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    ans = 0
    AB = a[i][0]*a[i][1]
    if a[i][0]<=a[i][1]:
        A, B = a[i][0], a[i][1]
    else:
        A, B = a[i][1], a[i][0]
    x = int(math.sqrt(AB-1))
    while x*x>=AB:
        x-=1
    if A==B:
        ans=2*A-2
    elif A+1==B:
        ans= 2*A-2
    elif x*(x+1)>=AB:
        ans = 2*x-2
    else:
        ans = 2*x-1
    print(ans)

Solution (Python):
import math
for _ in range(int(input())):
    a, b = map(int, input().split())
    a, b = max(a, b), min(a, b)
    p = a * b
    x = int(math.sqrt(p - 1))
    while x * x >= p:
        x -= 1
    c = x * 2
    if x * (x + 1) >= p:
        c -= 1
    if a <= x:
        c -= 1
    if b <= x:
        c -= 1
    print(c)

Solution (Python):
import math
n = int(input())
for i in range(n):
    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 = math.floor(math.sqrt(a * b))
        if c == math.sqrt(a*b):
            c -= 1
        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)

Solution (Python):
import math
I,j=int,input
q=I(j())
for i in[0]*q:
	a,b=map(I,j().split())
	c=I(math.sqrt(a*b))
	if c*(c+1)<a*b:print(2*c-1)
	elif (a*b==c*c)*(a!=b):print(2*c-3)
	else:print(2*c-2)

Solution (Python):
import math
I=int
j=input
q=I(j())
for i in[0]*q:
	a,b=map(I,j().split())
	c=I(math.sqrt(a*b))
	if c*(c+1)<a*b:print(2*c-1)
	elif (a*b==c*c)*(a!=b):print(2*c-3)
	else:print(2*c-2)

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

Solution (Python):
import math
I=int
q=I(input())
while q:
	a,b=map(I,input().split())
	c=I(math.sqrt(a*b))
	if c*(c+1)<a*b:print(2*c-1)
	elif (a*b==c*c)*(a!=b):print(2*c-3)
	else:print(2*c-2)
	q-=1

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

Solution (Python):
import math
Q = int(input())
for _ in range(Q):
	A,B = map(int,input().split())
	res = 0
	if A == B or A + 1 == B:
		res = 2 * A - 2
	else:
		C = int(math.sqrt(A * B))
		if C * C == A * B:
			C -= 1
		if C * (C + 1) >= A * B:
			res = 2 * C - 2
		else:
			res = 2 * C - 1
	print(res)

Solution (Python):
from numpy import sqrt

N = int(input())
for _ in range(N):
    a, b = map(int, input().split())
    score = a*b
    ans = 2*int(sqrt(score))
    if (ans//2) ** 2 == a*b:
        ans -= 2
    if a == b:
        ans = 2*a - 2
    else:
        if a > b:
            a, b = b, a

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

Solution (Python):
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if a*b==c*c and a!=b:  print(2*c-3)
    elif c*(c+1)<a*b: print(2*c-1)
    else:  print(2*c-2)

Solution (Python):
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c*(c+1)<a*b: print(2*c-1)
    elif a*b==c*c and a!=b:  print(2*c-3)
    else:  print(2*c-2)

Solution (Python):
import math
Q=input()

a=[]
for i in range(Q):
	x,y=map(int, raw_input().split())
	if x<=y:
		A=x
		B=y
	else:
		A=y
		B=x
	a.append((x,y))


for A,B in a:
	C=int(math.sqrt(A*B))
	if C**2<A*B:
		pass
	else:
		C-=1
	if A==B:		print 2*A-2
	elif A+1==B:		print 2*A-2
	elif C*(C+1)>=A*B:	print 2*C-2
	else:			print 2*C-1

Solution (Python):
import math

q = int(input())
a = []
b = []
for i in range(q):
  c = [int(i) for i in input().split()]
  a += [c[0]]
  b += [c[1]]

for i in range(q):
  prod = a[i] * b[i]
  sqrt = int(math.sqrt(prod))
  cnt = 2 * sqrt

  if a[i] == b[i]:
    cnt -= 2
  else:
    if sqrt * sqrt == prod:
      cnt -= 2
    elif prod // sqrt == sqrt:
      cnt -= 1
    elif prod // sqrt == sqrt + 1 and prod // sqrt * sqrt == prod:
      cnt -= 1
    cnt -= 1
  
  print(cnt)

Solution (Python):
import math

N = int(input().strip())
grid = []
for i in range(N):
	array = list(map(int, input().strip().split(' ')))
	grid.append(array)

for i in grid:
	i.sort()
	a,b = [i[0],i[1]]
	if(a == b or a+1 == b):
		print(2*a-2)
	else:
		c = int(math.sqrt(a*b))
		if c**2 == 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(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):
import math

q = int(input())
lis = [list(map(int, input().split())) for _ in range(q)]
for i in range(q):
	product = lis[i][0]*lis[i][1]
	rootInt = int(math.sqrt(product))
	if lis[i][0] == lis[i][1]:
		print((lis[i][0]-1)*2)
	elif math.sqrt(product) == rootInt:
		print((rootInt-2)*2+1)
	else:
		if rootInt*(rootInt+1) < product:
			print((rootInt-1)*2+1)
		else:
			print((rootInt-1)*2)

Solution (Python):
from math import sqrt

if __name__ == '__main__':
    Q = int(input())
    values = [list(map(int, input().split())) for _ in range(Q)]
    As, Bs = zip(*values)

    for A, B in zip(As, Bs):
        A, B = min(A, B), max(A, B)

        
        if A == B:
            print(2 * A - 2)
            continue

        
        if A + 1 == B:
            print((A - 2) + (B - 2) + 1)
            continue

        C = int(sqrt(A * B))
        if C == sqrt(A * B):
            C -= 1

        
        if C * (C + 1) >= A * B:
            print(2 * C - 2)
            continue

        
        if C ** 2 < A * B:
            print(2 * C - 1)
            continue

Solution (Python):
from math import sqrt

if __name__ == '__main__':
    Q = int(input())
    values = [list(map(int, input().split())) for _ in range(Q)]
    As, Bs = zip(*values)

    
    

    for A, B in zip(As, Bs):
        A, B = min(A, B), max(A, B)

        
        if A == B:
            print(2 * A - 2)
            continue

        
        if A + 1 == B:
            print((A - 2) + (B - 2) + 1)
            continue

        C = int(sqrt(A * B))
        if C == sqrt(A * B):
            C -= 1

        
        if C * (C + 1) >= A * B:
            print(2 * C - 2)
            continue

        
        if C ** 2 < A * B:
            print(2 * C - 1)
            continue

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 * d == c:
        answer -= 1
    if d * (d + 1) < c:
        answer += 1
    if a == b:
        answer += 1
    print(answer)