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

def derive_k(n):
  if n == 1:
    return 0
  lt = 1
  rt = n
  while rt - lt > 1:
    ct = (lt + rt) // 2
    if n >= ct * (ct+1):
      lt = ct
    else:
      rt = ct
  return lt  
  
for _ in range(Q):
  A, B = map(int,input().split())
  k = derive_k(A*B) 
  ans = k + (A*B-1)//(k+1) - 1
  
  if k+1 == A and k*(k+1) < A*B:
    ans += 1
  print(ans)

Solution (Python):
q=int(input())
ab=[list(map(int,input().split())) for _ in range(q)]
from math import floor
for a,b in ab:
    
    
    
    if a==b:
        print(2*a-2)
    else:
        
        
        t=floor((a*b)**0.5)
        
        if t*t>=a*b: 
            
            print(2*t-3)
        elif t*(t+1)>=a*b: 
            
            print(2*t-2)
        else:
            
            print(2*t-1)

Solution (Python):
def is_ok(x,n):
  if x**2<=n:
    return True
  else:
    return False

def meguru_bisect(ng, ok,n):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid,n):
      ok = mid
    else:
      ng = mid
  return ok

def sqrt(n):
  return meguru_bisect(n,1,n)

Q = int(input())
for _ in range(Q):
  A,B  = list(map(int,input().split()))
  score = A*B-1
  maxA = score//(B+1)
  maxB = score//(A+1)
  crit = sqrt(score)
  ans = 0
  if maxA:
    if crit<maxA:
      ans += crit+(score//(crit+1)-score//maxA)+1
    else:
      ans += maxA
  if maxB:
    if crit<maxB:
      ans += crit+(score//(crit+1)-score//maxB)+1
    else:
      ans += maxB
  print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]



def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





def is_ok(x,n):
  if x**2<=n:
    return True
  else:
    return False

def meguru_bisect(ng, ok,n):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid,n):
      ok = mid
    else:
      ng = mid
  return ok

def sqrt(n):
  return meguru_bisect(n,1,n)

Q = I()
for _ in range(Q):
  A,B  = IL()
  score = A*B
  maxA = (score-1)//(B+1)
  maxB = (score-1)//(A+1)
  crit = sqrt(score-1)
  ans = 0
  if maxA:
    if crit<maxA:
      ans += crit+((score-1)//(crit+1)-(score-1)//maxA)+1
    else:
      ans += maxA
  if maxB:
    if crit<maxB:
      ans += crit+((score-1)//(crit+1)-(score-1)//maxB)+1
    else:
      ans += maxB
  print(ans)

Solution (Python):
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    
    
    def square_range(a, b):
        left = a
        right = b - 1
        while left < right:
            center = (left + right + 1) // 2
            if center * center < a * b:
                left = center
            else:
                right = center - 1
        return left

    q = int(input())
    ans = [0] * q

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

        if a < b:
            mid = square_range(a, b)
        else:
            mid = square_range(b, a)

        if mid * (mid + 1) < a * b:
            ans[lap] = (2 * mid - 1)
        else:
            ans[lap] = (2 * mid - 2)
    
    for i in ans:
        print(i)

main()

Solution (Python):
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    
    
    def square_range(a, b):
        left = a
        right = b - 1
        while left < right:
            center = (left + right + 1) // 2
            if center * center < a * b:
                left = center
            else:
                right = center - 1
        return left

    q = int(input())
    ans = [0] * q

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

        if a < b:
            mid = square_range(a, b)
        else:
            mid = square_range(b, a)

        if mid * (mid + 1) < a * b:
            ans[lap] = (2 * mid - 1)
        else:
            ans[lap] = (2 * mid - 2)
    
    for i in ans:
        print(i)

main()

Solution (Python):
for q in range(int(input())):
  A,B = sorted(map(int,input().split()))
  if B-A<=1:
    print(2*A-2)
  else:
    X = int((A*B)**.5)
    X -= A*B == X*X
    print(2*X-1-(X*(X+1)>=A*B))

Solution (Python):


import math

q = int(input())
ab = [list(map(int, input().split())) for i in range(q)]

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

    value = int((a*b)**0.5)

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

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

q=int(input())
ab=[list(map(int,input().split())) for i in range(q)]

for i,j in ab:
    i,j=min(i,j),max(i,j)
    if i==j:
        print(2*i-2)
    elif i+1==j:
        print(2*i-2)
    else:
        ne=int((i*j)**0.5)
        if ne*ne==i*j:
            ne-=1
        if ne*(ne+1)>=i*j:
            print(2*ne-2)
        else:
            print(2*ne-1)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


def g(c):  
    left = 0  
    right = c  
    while left + 1 < right:
        mid = (left + right)//2
        if mid*(mid+1) <= c:
            left = mid
        else:
            right = mid
    return left


def query(a,b):
    if a == b:
        return a+b-2
    if a > b:
        a,b = b,a
    i0 = g(a*b)
    return i0+(a*b-1)//(i0+1)-1


Q = I()
for i in range(Q):
    a,b = MI()
    print(query(a,b))

Solution (Python):
from math import sqrt
N=int(input())
for i in range(N):
    A,B=map(int,input().split())
    if A==B:
        print(2*(A-1))
    else:
        if A>B:
            A,B=B,A
        s=int(sqrt(A*B-1))+5
        for j in range(s,s-10,-1):
            if j**2<A*B:
                s=j
                break
        a=s*2-1
        if s*(s+1)>=A*B:
            a-=1
        print(a)

Solution (Python):
from math import sqrt
Q=int(input())
for i in range(Q):
    A,B=map(int,input().split())
    if A==B:
        print(2*(A-1))
        continue
    t=A*B
    s=int(sqrt(t))+5
    for j in range(s,s-10,-1):
        if j**2<t:
            s=j
            break
    if s*(s+1)<t:
        print(s*2-1)
    else:
        print(s*2-2)

Solution (Python):
import math


def solve(A, B):
    A, B = min(A, B), max(A, B)
    if B - A <= 1:
        return 2 * A - 2
    C = math.floor(math.sqrt(A * B)) - 1
    while (C + 1) ** 2 < A * B:
        C += 1
    if C * (C + 1) >= A * B:
        return 2 * C - 2
    else:
        return 2 * C - 1


def main():
    Q = int(input())
    query_list = [list(map(int, input().split())) for _ in range(Q)]
    ans = [solve(a, b) for a, b in query_list]
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    q = int(ipt())
    for _ in range(q):
        a,b = map(int,ipt().split())
        if a > b:
            a,b = b,a
        tgt = a*b
        rt = int(tgt**0.5+0.0000000000001)
        ans = rt*2-1
        if a == b:
            ans -= 1
        elif rt**2 == tgt:
            ans -= 2
        elif rt*(rt+1) < tgt:
            pass
        elif rt**2-1 < tgt:
            ans -= 1
        print(ans)

    return None

if __name__ == '__main__':
    main()

Solution (Python):
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

def f(x,y):
    ma = x*y - 1
    ok = 0
    ng = 10**9 + 1
    while ng - ok > 1:
        mid = (ok+ng)//2
        if mid**2 <= ma:
            ok = mid
        else:
            ng = mid
    return ok

ans = []
for testcase in range(Q):
    a,b = map(int,input().split())
    if a == 1 and b == 1:
        ans.append(0)
        continue
    p = f(a,b)
    res = p*2
    if a != b:
        res -= 1
    if p == (a*b - 1)//p:
        res -= 1
    ans.append(res)

print(*ans,sep='\n')

Solution (Python):
for _ in range(int(input())):
  a,b=map(int,input().split())
  if abs(a-b)<=1:print(min(a,b)*2-2)
  else:
    c=int((a*b)**0.5)
    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 sys
import math
def input(): return sys.stdin.readline().rstrip()


def solve(x, y):
    if x == y:
        return 2*x-2
    else:
        k = x*y
        sqr = math.ceil(math.sqrt(k))-1
        return 2*sqr-2+(sqr*(sqr+1) < k)


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



if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
def input(): return sys.stdin.readline().rstrip()


def solve(x, y):
    if x == y:
        return 2*x-2
    elif abs(x-y)==1:
        return min(x,y)*2-2
    else:
        k = x*y
        sqr = math.ceil(math.sqrt(k))-1
        return 2*sqr-2+(sqr*(sqr+1) < k)


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


if __name__ == '__main__':
    main()

Solution (Python):
Q=int(input())
AB=[list(map(int,input().split())) for i in range(Q)]
for a,b in AB:
    x=int((a*b)**.5)
    if x*x==a*b:
        x-=1
    if max(a,b)-min(a,b)<2:
        print(2*min(a,b)-2)
    elif a*b<=x*(x+1):
        print(2*x-2)
    else:
        print(2*x-1)

Solution (Python):
import math
Q=int(input())
for _ in range(Q):
  A,B=map(int,input().split())
  if abs(A-B)<2:
    print(min(A,B)*2-2)
  else:
    s=int(math.ceil(math.sqrt(A*B)))-1
    if s**2+s<A*B:
      print(2*s-1)
    else:
      print(2*s-2)

Solution (Python):
from math import sqrt

def main():
    q = int(input())
    ans = [None]*q
    for i in range(q):
        a, b = map(int, input().split())
        score = a*b
        tmp = 0
        if b < a:
            a, b = b, a
        if a == b:
            tmp = (a-1) + (b-1)
        elif a+1 == b:
            tmp = (a-1) + (a-1)
        else:
            p = int(sqrt(score))
            if p**2 == score:
                p -= 1
            tmp = 2*p - 1
            if p * (p+1) >= score:
                tmp -= 1
        ans[i] = tmp
    for v in ans:
        print(v)

if __name__ == "__main__":
    main()

Solution (Python):
import math
q=int(input())
for i in range(q):
 a,b=map(int,input().split())
 if abs(a-b)<2:print(min(a,b)*2-2)
 else:
  s=int(math.ceil(math.sqrt(a*b)))-1
  if s**2+s<a*b:print(2*s-1)
  else:print(2*s-2)

Solution (Python):
for a in[*open(0)][1:]:a,b=map(int,a.split());c=int((a*b)**.5);print((a*b-(a!=b))//c+c-2)

Solution (Python):
for a in[*open(0)][1:]:a,b=map(int,a.split());c=a*b;d=int(c**.5);print(~(d*-~d>=c)+d+d-(c==d*d>0<a!=b))

Solution (Python):
import sys
input = sys.stdin.readline
Q = int(input())
AB = [list(map(int,input().split())) for i in range(Q)]

small_case = {(1,1):0, (1,2):0}
for A,B in AB:
    M = A*B
    A,B = sorted([A,B])
    if (A,B) in small_case:
        print(small_case[(A,B)])
        continue
    ans = 0
    i = 1
    b = int(pow(M,0.5))
    if b == B:
        b -= 1
    ans += (M-1)//b - A
    ans += b-1
    ans += A-1
    print(ans)

Solution (Python):
def main():
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        ref = a * b - 1
        rng = int(ref ** 0.5) - 2
        while rng ** 2 < a * b:
            rng += 1
        rng -= 1
        if a == b or abs(a - b) == 1:
            print(2 * min(a, b) - 2)
        elif rng * (rng + 1) >= a * b:
            print(2 * rng - 2)
        else:
            print(2 * rng - 1)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def prod_max(a, d, b, e, n):
    """
    初項a、公差dの等差数列および初項b、公差eの等差数列を各項ごとに
    掛け合わせた時の第0項から第n項までの最大値を返す。
    a>0, d>0, b>0, e<0を仮定する。
    """
    if n < 0: return 0
    idx = round((-(b / e) - (a / d)) / 2)
    if idx < 0: return a * b
    if idx <= n: return (a + idx * d) * (b + idx * e)
    return (a + n * d) * (b + n * e)

def main():
    """
    解説放送にしたがって決め打ち二分探索による実装。
    まずa<=bを仮定しても良い。a*bよりも小さい積がX個作れるかを考える。
    これは1, 2, ..., a-1, a+1, ...からX個、1, 2, ..., b-1, b+1, ...からX個選んで
    小さいものと大きいもののペアで積を取ったものが全てa*b未満であることをいえば良い。

    積を実際に全て計算していては間に合わないが、実質これは等差数列の積なので
    これらの積のうち最大値はO(1)で計算可能。
    """
    Q = int(input())
    for _ in range(Q):
        a, b = map(int, input().split())
        if a > b: a, b = b, a

        
        left = a - 1
        right = 10 ** 10
        while right - left > 1:
            mid = (left + right) // 2
            if mid < b:
                """
                この時ペアリングは
                1*mid, 2*(mid-1), ..., (a-1)*(mid-a+1), (a+1)*(mid-a), ..., (mid+1)*1
                前半後半でそれぞれ最大値を取得する。
                """
                cand1 = prod_max(1, 1, mid, -1, a-2)
                cand2 = prod_max(a+1, 1, mid-a+1, -1, mid-a)
                if cand1 < a * b and cand2 < a * b: left = mid
                else: right = mid
                
            elif mid < a + b - 1:
                """
                この時ペアリングは
                1*(mid+1), 2*mid, ..., (mid-b+1)*(b+1),
                (mid-b+2)*(b-1), ..., (a-1)*(mid-a+2),
                (a+1)*(mid-a+1), ..., (mid+1)*1
                より3つに分けて最大値を求める。
                """
                cand1 = prod_max(1, 1, mid+1, -1, mid-b)
                cand2 = prod_max(mid-b+2, 1, b-1, -1, a+b-mid-3)
                cand3 = prod_max(a+1, 1, mid-a+1, -1, mid-a)
                if cand1 < a * b and cand2 < a * b and cand3 < a * b: left = mid
                else: right = mid
                
            else:
                """
                この時ペアリングは
                1*(mid+1), 2*mid, ..., (mid-a+3)*(a-1),
                (a+1)*(mid-a+2), ..., (mid-b+2)*(b+1),
                (mid-b+3)*(b-1), ..., (mid+1)*1
                より3つに分けて最大値を求める。
                """
                cand1 = prod_max(1, 1, mid+1, -1, a-2)
                cand2 = prod_max(a+1, 1, mid-a+2, -1, mid-a-b+1)
                cand3 = prod_max(mid-b+3, 1, b-1, -1, b-2)
                if cand1 < a * b and cand2 < a * b and cand3 < a * b: left = mid
                else: right = mid
                
        print(left)


if __name__ == "__main__":
    main()

Solution (Python):
from decimal import *
Q = int(input())

for i in range(Q):
  a, b = map(int, input().split())
  a = Decimal(a)
  b = Decimal(b)
  m = int((Decimal(a * b) - 1) ** Decimal(1 / 2))
  ans = 2 * m
  if a == b:
    ans -= 0
  else:
    if int((Decimal(a * b) - Decimal(1)) / Decimal(m)) == m:
      ans -= 2
    else:
      ans -= 1
  print(ans)

Solution (Python):
q=int(input())
for _ in range(q):
    a_,b_=map(int,input().split())
    a=min(a_,b_)
    b=max(a_,b_)
    ng=b+1
    ok=1
    while ng-ok>1:
        mid=(ok+ng)//2
        m=-(-(a+mid)//2)
        if m==a:
          m-=1
        if (a+mid-m)*m<a*b:
            ok=mid
        else:
            ng=mid
    print(a+ok-2)

Solution (Python):
from math import floor
q = int(input())
ab=[list(map(int,input().split())) for _ in range(q)]
for a,b in ab:
    if a==b:
        print(2*a-2)
        continue
    t = floor((a*b)**0.5)
    if t*t >=a*b:
        print(2*t-3)
    elif t*(t+1)>=a*b:
        print(2*t-2)
    else:
        print(2*t-1)

Solution (Python):
q=int(input())
ab=[list(map(int,input().split())) for _ in range(q)]
from math import floor
for a,b in ab:
  if a==b:
    print(2*a-2)
    continue
  t=floor((a*b)**0.5)
  
  if t*t>=a*b: 
    print(2*t-3)
  elif t*(t+1)>=a*b: 
    print(2*t-2)
  else: 
    print(2*t-1)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1) * 2
    elif b == a+1:
        ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5) - 2
        while (c+1) ** 2 < a*b:
            c += 1
        
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

print('\n'.join(map(str, answer)))

Solution (Python):
from math import sqrt

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


def sqrtfloor(x):
    s = int(sqrt(x))
    if s ** 2 == x:
        s -= 1
    return s


def solve(a, b):
    a, b = min(a, b), max(a, b)
    if a == b or a + 1 == b:
        return 2 * a - 2
    else:
        s = sqrtfloor(a * b)
        if s * (s + 1) < a * b:
            return 2 * s - 1
        else:
            return 2 * s - 2


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

Solution (Python):
def binsearch(good, bad, fn):
    while abs(good - bad) > 1:
        m = (good + bad) // 2
        if fn(m):
            good = m
        else:
            bad = m
    return good

def solve(a, b):
    if a > b:
        a, b = b, a
    if a == b:
        return 2 * (a - 1)
    t = binsearch(1, a * b, lambda x: (x + 1) // 2 * (x // 2 + 1) < a * b)
    return t - 1

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


q = int(input())
ans = []
def sub(a,b):
    if a==b:
        ans = 2*a-2
    elif abs(a-b)==1:
        ans = min(a,b)*2-2
    else:
        l = 0
        r = a*b
        while l<r-1:
            m = (l+r)//2
            if m**2<a*b:
                l = m
            else:
                r = m
        a,b = max(a,b), min(a,b)
        ans = 2*l-2
        if l*(l+1)<a*b:
            ans += 1
    return ans
    
for i in range(q):
    a,b = map(int, input().split())
    ans.append(sub(a,b))
write("\n".join(map(str, ans)))

Solution (Python):
import math

Q = int(input())

for i in range(Q):
  A, B = map(int, input().split())
  ABsq = math.ceil((A*B)**(1/2))
  if A == B:
    print(2*(A-1))
  else:
    if ABsq*(ABsq-1) >= A*B:
      print(2*(ABsq-1)-2)
    else:
      print(2*(ABsq-1)-1)

Solution (Python):
def check(a, b, mid):
  k = min(mid, (a + mid + 1) // 2)
  return (a + mid + 1 - k) * k < a * b

def solve(a, b):
  ok = 0
  ng = b
  while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(a, b, mid):
      ok = mid
    else:
      ng = mid
  return a - 1 + ok

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    Q=int(input())
    for _ in range(Q):
        a,b=map(int,input().split())
        if a==b:
            print(a+b-2)
            continue
        
        ans=0
        if a<b:
            a,b=b,a
        ans+=b-1
        def nibutan(ok,ng):
            while abs(ok-ng) > 1:
                mid = (ok + ng) // 2
                if solve(mid):
                    ok = mid
                else:
                    ng = mid
            return ok
        
        def solve(mid):
            return mid**2<a*b
        
        sq=nibutan(0,10**9)
        if sq*(sq+1)<a*b:
            p,q=sq,sq+1
        else:
            p,q=sq,sq
        ans+=q-b
        ans+=p-1
        print(ans)
        
                

if __name__ == '__main__':
    main()

Solution (Python):
import math
q=int(input())
A=[]
for i in range(q):
    a,b=map(int,input().split())
    p=max(a,b)
    q=min(a,b)
    ans=q-1
    if p-q==1:
        now=q-1
    else:
        now=p-1
    if q>now:
        ans+=now
    else:
        s=int(math.sqrt(a*b))
        if s*(s+1)<a*b:
            ans+=(s-q+1)+s-1
        elif s*s<a*b:
            ans+=(s-q+1)+s-2
        else:
            ans+=(s-1-q+1)+s-2
    A.append(ans)
print(*A,sep="\n")

Solution (Python):
from itertools import combinations_with_replacement
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)
    criteria=a*b
    left,right=a,b
    while right>left+1:
        mid=(left+right)//2
        if mid**2>criteria:right=mid
        else:left=mid

    cnt,point=0,0
    for i,j in enumerate(combinations_with_replacement([left,right],2)):
        if point<j[0]*j[1]<=criteria:
            point=j[0]*j[1]
            cnt=i

    if cnt==0:
        if point==criteria and a!=b:print((left-1)*2-1)
        else:print(left*2-2)
    else:
        if point==criteria:print(left*2-2)
        else:print(left*2-1)

Solution (Python):
from itertools import combinations_with_replacement
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)
    criteria=a*b
    left,right=a,b
    while right>left+1:
        mid=(left+right)//2
        if mid**2>criteria:right=mid
        else:left=mid

    cnt,point=0,0
    for i,j in enumerate(combinations_with_replacement([left,right],2)):
        if point<j[0]*j[1]<=criteria:
            point=j[0]*j[1]
            cnt=i

    
    if cnt==0:
        if point==criteria:
            if a!=b:print((left-1)*2-1)
            else:print(left*2-2)
        else:print(left*2-2)
    else:
        if point==criteria:print(left*2-2)
        else:print(left*2-1)

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

Solution (Python):
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    if a == b:
        print(2*a-2)
    elif abs(a-b) == 1:
        print(min(a,b)*2-2)
    else:
        c = int((a*b)**0.5)
        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
q = int(input())
for i in range(q):
  a,b = map(int,input().split())
  if a == b:
    print(a*2-2)
    continue
  y = max(a,b)
  z = min(a,b)
  ind = math.sqrt(a*b)
  d = int(ind)
  if ind.is_integer():
    d -= 1
  cnt = 0
  if d*(d+1) < a*b:
    if d >= z:
      cnt = 1
    if d+1 >= y:
      cnt = 2
    print(2*d-cnt)
  else:
    if d >= z:
      cnt = 1
    print(2*d-1-cnt)

Solution (Python):
q = int(input())
for i in range(q):
  a,b = map(int,input().split())
  if a == b:
    print(2*a-2)
  else:
    n= (a*b)**0.5
    d = int(n)
    if n.is_integer():
        d -= 1
    ans = d*2-1
    if d*(d+1) >= a*b:
      ans -= 1
    print(ans)

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

ans = []
for _ in range(Q):
    A, B = map(int, input().split())

    if A == B:
        ans.append(2 * A - 2)
        continue

    C = (A * B)**0.5
    D = int(C)

    if C.is_integer():
        D -= 1

    F = 2 * D - 1
    if D * (D + 1) >= A * B:
        F -= 1

    ans.append(F)

print(*ans, sep='\n')

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

ans = []
for _ in range(Q):
    A, B = map(int, input().split())

    if A == B:
        ans.append(2 * A - 2)
        continue

    C = (A * B)**0.5
    D = int(C)

    if D**2 == A * B:
        D -= 1

    F = 2 * D - 1
    if D * (D + 1) >= A * B:
        F -= 1

    ans.append(F)

print(*ans, sep='\n')

Solution (Python):


q = int(input())
info = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    min_, max_ = info[i]
    min_, max_ = min(min_, max_), max(min_, max_)
    
    
    if min_ == 1 and max_ == 1:
        print(0)
        continue

    mul = min_ * max_
    ans = 2 * (min_ - 1)

    ok = 0
    ng = max_ + 10
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid <= (mul - 1) // mid:
            ok = mid
        else:
            ng = mid
    ans += max(ok - (min_ - 1), 0)
    ans += max(ok - min_, 0)
    
    if ok == (mul - 1) // ok:
        ans -= 1
    print(ans)

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

def solve(nim,mike):
    if nim == mike:
        return 2*nim-2
    if mike < nim:
        return solve(mike, nim)

    lb, ub, ab = nim, 2*mike, nim*mike
    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(data):
    nim, mike = map(int, input().split())
    print(solve(nim,mike))

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def sqrt(n: int):
    lb = 0
    rb = n + 1
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if m * m > n:
            rb = m
        else:
            lb = m
    return lb


def solve(Q: int, A: "List[int]", B: "List[int]"):
    for Ai, Bi in zip(A, B):
        a = sqrt(Ai * Bi)
        b = a + 1 if a * (a + 1) <= Ai * Bi else a

        def f(a: int, b: int):
            m = a + b - 2
            if a * b == Ai * Bi:
                m -= b - a + 1
                if {a, b} == {Ai, Bi}:
                    m += 1
            return m

        print(max(f(a, b), f(a, b - 1)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  
    A = [int()] * (Q)  
    B = [int()] * (Q)  
    for i in range(Q):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(Q, A, B)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

Q = int(input())
for _ in range(Q):
    A, B = map(int, input().split())
    if A > B:
        A, B = B, A
    ans = (A - 1) * 2
    lb, ub = A, B
    while ub - lb > 1:
        m = (lb + ub) // 2
        x = (A+1+m) // 2
        if (m - A) % 2 == 0:
            if x*x >= A*B:
                ub = m
            else:
                lb = m
        else:
            if x*(x-1) >= A*B:
                ub = m
            else:
                lb = m
    ans += lb - A
    print(ans)

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

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

    l = 1
    r = 10 ** 10
    while r - l > 1:
        m = (l + r) // 2
        mx = (m + 1) // 2 * (m + 1 - (m + 1) // 2)
        if mx < a * b:
            l = m
        else:
            r = m

    print(l - 1)

Solution (Python):
eps = 10**-7

def check(a, b):
  if b < a:
    a, b = b, a
  if b - a <= 1:
    return 2 * a - 2
  c = int((a*b)**.5 - eps)
  return 2 * c - 1 - (c * (c + 1) >= a * b)

for _ in range(int(input())):
  print(check(*list(map(int, input().split()))))

Solution (Python):
from math import sqrt

eps = 10**-7

def check(a, b):
  if b < a:
    a, b = b, a
  if b - a <= 1:
    return 2 * a - 2
  c = int(sqrt(a*b) - eps)
  assert(c**2 < a*b <= (c+1)**2)
  return 2 * c - 1 - (c * (c + 1) >= a * b)

for _ in range(int(input())):
  print(check(*list(map(int, input().split()))))