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):
def getKth(x, a, k):
    if(k < a):
        return k
    return k + 1
def getRKth(x, a, k):
    if(x < a):
        return x - k + 1
    if(k < (x - a)):
        return x - k + 1
    return x - k
def NB(x, b):
    if(x < b):
        return x
    return x + 1
def f(x, a, b):
    half = (x + 1) / 2
    rep = 0
    for delta in xrange(-50, 51):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    half = b - a
    for delta in xrange(-50, 51):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    half = NB(x, b) - b
    for delta in xrange(-50, 51):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    return rep
q = int(raw_input())
while(q > 0):
    a, b = map(int, raw_input().split())
    if(a > b):
        a, b = b, a
    lo = 1
    hi = 10**19
    res = 0
    
    
    
    
    
    while(lo <= hi):
        mid = (lo + hi)/2
        if(f(mid, a, b) < a * b):
            lo = mid + 1
            res = mid
        else:
            hi = mid - 1
    print res
    q -= 1

Solution (Python):


import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq





def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

def solve(f):
    q = f.read_int()

    res = []
    for _ in xrange(q):
        a, b = f.read_int_list()
        if a*b == 1:
            res.append("0")
            continue
        sq = isqrt(a*b-1)
        ans = sq*2
        if (a*b-1)/sq == sq: ans -= 1
        if a <= sq: ans -= 1
        if b <= sq: ans -= 1
        res.append(str(ans))

    return "\n".join(res)


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case 
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    rr = []
    for _ in range(n):
        a,b = LI()
        t = a*b
        s = int(t ** 0.5)
        if t < 3:
            rr.append(0)
        elif a == b:
            if (a-1) * (b+1) < t:
                rr.append((a-1)*2)
            else:
                rr.append((a-1)*2-1)
        elif s*s == t:
            rr.append((s-1)*2-1)
        elif s*(s+1) < t:
            rr.append(s*2-1)
        else:
            rr.append((s-1)*2)


    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
from math import sqrt

q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    m = a * b
    s = int(sqrt(m))
    ans = 2 * s - 1
    if s * (s + 1) >= m:
        ans -= 1
    if s * s == m and a != b:
        ans -= 1
    print(ans)