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.



Sample input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323


Sample output:
1
12
4
11
14
57
31
671644785

Submission status: Wrong Answer

Solution code:
#!python3

# input
Q = int(input())
A, B = [None] * Q, [None] * Q
for i in range(Q):
    A[i], B[i] = sorted(map(int, input().split()))


def solve(a, b):
    w = a * b - 1
    left, right = 0, b - a
    while right - left > 1:
        x = (left + right) // 2
        v = w // (a + x)
        if v < a:
            right = x
        else:
            left = x

    n = left
    left, right = 0, n + 1
    while right - left > 1:
        x = (left + right) // 2
        d = (w // (a + x)) - (w // (a + x + 1))
        if d > 0:
            left = x
        else:
            right = x
    
    return left - 1 + (w // (a + left)) - (w // (a + n))


def main():
    for a, b in zip(A, B):
        ans = 2 * (a - 1) + solve(a, b)
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
q=int(input())
for i in range(q):
  a,b=map(int,input().split())
  s=a*b
  ans=s//(a+1)+s//(b+1)
  if s%(a+1)==0:ans-=1
  if s%(b+1)==0:ans-=1
  print(ans)

Submission status: Wrong Answer

Solution code:
q = int(input())
for i in range(q):
  x,y = map(int,input().split())
  if x == y:
    print(2*(x-1))
    continue
  z = int((x*y)**0.5-10**-14)
  ans = 2*z-2
  if z*(z+1)<x*y:
    ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
q = int(input())
for i in range(q):
  x,y = map(int,input().split())
  if x == y:
    print(2*(x-1))
    continue
  z = int((x*y)**0.5-10**-10)
  ans = 2*z-2
  if z*(z+1)<x*y:
    ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

q=I()

def check(k,a,b):
    if a<b:
        a,b=b,a
    s=(k+1)//2-3
    
    for i in range(max(s,1),min(s+8,k+1)):
        c=i
        d=k+1-i
        if c>=a:
            c+=1
        if d>=b:
            d+=1
        if c*d>=a*b:
            return False
    return True
    
def solve(a,b):
    l,r=0,10**9
    while r-l>1:
        mid=(l+r)//2
        if check(mid,a,b):
            l=mid
        else:
            r=mid
    return l
    
for i in range(q):
    a,b=LI()
    print(solve(a,b))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

q=I()

def check(k,a,b):
    if a<b:
        a,b=b,a
    s=(k+1)//2-3
    
    for i in range(max(s,1),min(s+8,k+2)):
        c=i
        d=k+1-i
        if c>=a:
            c+=1
        if d>=b:
            d+=1
        if c*d>=a*b:
            return False
    return True
    
def solve(a,b):
    l,r=0,10**9
    while r-l>1:
        mid=(l+r)//2
        if check(mid,a,b):
            l=mid
        else:
            r=mid
    return l
    
for i in range(q):
    a,b=LI()
    print(solve(a,b))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

q=I()

def check(k,a,b):
    if a<b:
        a,b=b,a
    s=(k+1)//2-3
    
    for i in range(max(s,1),min(s+5,k+2)):
        c=i
        d=k+1-i
        if c>=a:
            c+=1
        if d>=b:
            d+=1
        if c*d>=a*b:
            return False
    return True
    
def solve(a,b):
    l,r=0,10**9
    while r-l>1:
        mid=(l+r)//2
        if check(mid,a,b):
            l=mid
        else:
            r=mid
    return l
    
for i in range(q):
    a,b=LI()
    print(solve(a,b))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

q=I()

def check(k,a,b):
    if a<b:
        a,b=b,a
    s=(k+1)//2-3
    
    for i in range(max(s,1),min(s+5,k+2)):
        c=i
        d=k+2-i
        if c>=a:
            c+=1
        if d>=b:
            d+=1
        if c*d>=a*b:
            return False
    return True
    
def solve(a,b):
    l,r=0,10**9
    while r-l>1:
        mid=(l+r)//2
        if check(mid,a,b):
            l=mid
        else:
            r=mid
    return r
    
for i in range(q):
    a,b=LI()
    print(solve(a,b))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

q=I()

def check(k,a,b):
    if a>b:
        a,b=b,a
    s=(k+1)//2-2
    
    k+=1
    c,d=k//2,k//2+1
    if c*d<a*b:
        return True
    else:
        return False
    
    
def solve(a,b):
    l,r=0,10**9
    while r-l>1:
        mid=(l+r)//2
        if check(mid,a,b):
            l=mid
        else:
            r=mid
    return l
    
for i in range(q):
    a,b=LI()
    print(solve(a,b))

Submission status: Wrong Answer

Solution code:

def bsearch(target, min_i, max_i, func):
    # func(index) <= target < func(index+1) となるindexを返す
    if func(max_i) < target:
        return max_i
    if target <= func(min_i):
        return None
    index = (max_i + min_i)//2
    while True:
        if max_i - min_i <= 1:
            return min_i
        if func(index) < target:
            index, min_i = (index + max_i)//2, index
            continue
        index, max_i = (index + min_i)//2, index


def f(N):
    def g(i):
        if i < I or J < i:
            return i*(N-i+2)
        elif i == I:
            return 0
        else:
            return i*(N-i+1)
    I, J = sorted([A,N-B+1])
    return max(g(N//2), g(N//2+1), g(N//2+2))

Q, = map(int, input().split())
for _ in range(Q):
    A, B = map(int, input().split())
    r = bsearch(A*B, 1, A*B, f)
    print(r)

Submission status: Wrong Answer

Solution code:
def bsearch(target, min_i, max_i, func):
    # func(index) <= target < func(index+1) となるindexを返す
    if func(max_i) < target:
        return max_i
    if target <= func(min_i):
        return None
    index = (max_i + min_i)//2
    while True:
        if max_i - min_i <= 1:
            return min_i
        if func(index) < target:
            index, min_i = (index + max_i)//2, index
            continue
        index, max_i = (index + min_i)//2, index

def f(N):
    I, J = sorted([A,N-B+1])
    cs = []
    if not(I == J and I == N//2 + 1):
        c = N//2 + 1
    else:
        c = N//2 + 2
    return max(c*(N-c+1), c*(N-c))

Q, = map(int, input().split())
for _ in range(Q):
    A, B = map(int, input().split())
    r = bsearch(A*B, 1, A*B, f)-1
    print(r)

Submission status: Wrong Answer

Solution code:

def bsearch(target, min_i, max_i, func):
    # func(index) <= target < func(index+1) となるindexを返す
    if func(max_i) < target:
        return max_i
    if target <= func(min_i):
        return None
    index = (max_i + min_i)//2
    while True:
        if max_i - min_i <= 1:
            return min_i
        if func(index) < target:
            index, min_i = (index + max_i)//2, index
            continue
        index, max_i = (index + min_i)//2, index

def f(N):
    I, J = sorted([A,N-B+1])
    J = N-B+1
    cs = []
    if not(I == J and I == N//2 + 1):
        c = N//2 + 1
    else:
        c = N//2 + 2
    return max(c*(N-c+1), c*(N-c))

Q, = map(int, input().split())
for _ in range(Q):
    A, B = map(int, input().split())
    r = bsearch(A*B, 1, A*B, f)-1
    print(r)

Submission status: Wrong Answer

Solution code:
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examD()

Submission status: Wrong Answer

Solution code:
q=int(input())
ab=[list(map(int,input().split())) for i in range(q)]
for u in ab:
    ans=0
    a,b=u
    if a==b==1:
        print(0)
        continue
    if a==b==2:
        print(0)
        continue
    if a==b:
        print(2*(a-1))
        continue
    if a>b:
        a,b=b,a
    c=a*b-1
    d=int(c**(1/2))
    print(d)
    if d*(d+1)<=c:
        ans=2*d
    else:
        ans=2*d-1
    ans-=1
    if c//(b+1)==c//b or c//(b+1)==c//b:
        print(ans)
    else:
        print(ans-1)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

    p=int((a*b)**(1/2))
    print(p)
    if p*(p+1) < a*b:
        ans=int(2*p-1)
    elif p**2==a*b and not a==b:
        ans=int(2*p-3)
    else:
        ans=int(2*p-2)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for (u, v) in uvs:
    z = math.floor(math.sqrt(u*v - 1))
    if z*(z+1) < u*v:
        ans = 0
        x = z
        y = z+1
    elif z in (u, v):
        ans = 0
        x = z-1
        y = z
    else:
        ans = 1
        x = z-1
        y = z+1

    for a, b in [(u, v), (v, u)]:
        ans += x
        t = y

        if a <= x:
            ans = ans - 1
            t = t - 1
        if t <= b and b <= y+t-1 and (x - (b-t)) * (b+1) >= u*v:
            ans = ans - 1

    print(ans)

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]
Q = int(input())
for _ in range(Q):
    A, B = sorted(inpl())
    c = int(-(-(A*B)**0.5//1)-1)
    ans = A-1 + max(0, c-A) + (-(-A*B)//(c+1)-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]
Q = int(input())
for _ in range(Q):
    A, B = sorted(inpl())
    c = int((A*B-1)**0.5//1)
    ans = c-1+(A*B-1)//(c+1)
    print(ans + ((A*B)//1 == -((-A*B)//1)))

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]
Q = int(input())
for _ in range(Q):
    A, B = sorted(inpl())
    c = int((A*B-1)**0.5//1)
    ans = c-1+(A*B-1)//(c+1)
    print(ans+ (A == B))

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = []
for T in range(N):
	c = list(map(int, input().split()))
	pro = c[0] * c[1]
	sq = int(pro**0.5)
	if c[0] == c[1]:
		n = (sq - 1) * 2
	elif (c[0]%2 != 0 and c[1]%2 == 0) or (c[1]%2 != 0 and c[0]%2 == 0):
		n = (sq - 1) * 2
	elif (c[0]%2 == 0 and c[1]%2 == 0):
		n = (sq * 2) - 1 
	else: 
		n = (sq * 2) - 2
	lis.append(n)
for i in lis:
	print(i)

Submission status: Wrong Answer

Solution code:
import math
import random
Q = int(input()) 


for _ in range(Q):
    a,b = [int(x) for x in input().split()]
    seki = a*b - 1
    saidai = math.floor(seki**0.5)
    result = saidai*2
    if saidai*(saidai+1) > seki:
        result -= 1
    if a <= saidai or b <= saidai:
        result -= 1
    print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt 
Q = int(input())
table=[]
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        table.append([B,A])
    else:
        table.append([A,B])
def f(a,b):
    if a==b:
        return 2*a-2
    if a+1==b:
        return 2*a-2
    m = int(sqrt(a*b))
    if m*2 ==a*b:
        m-=1
    if m*(m+1) >= a*b:
        return 2*m -2
    return 2*m-1

ans = []
for a,b in table:
    ans.append(f(a,b))
print('\n'.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
from math import sqrt 
Q = int(input())
table=[]
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        table.append([B,A])
    else:
        table.append([A,B])
def f(a,b):
    if a==b:
        return 2*a-2
    if a+1==b:
        return 2*a-2
    m = int(sqrt(a*b))
    if m*2 ==a*b:
        return 2*m-3
    if m*(m+1) >= a*b:
        return 2*m -2
    return 2*m-1

ans = []
for a,b in table:
    ans.append(f(a,b))
print('\n'.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
import math 
Q=int(input())
table=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        table.append([b,a])
    else:
        table.append([a,b])
ans=[]
for a,b in table:
    s = int(math.sqrt(a*b))
    num=2*s-2
    if s-1>=a:
        num-=1
    if s*(s+1)<a*b:
        num+=2
    elif s*s<a*b:
        num+=1
    ans.append(num)
print('\n'.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
q=int(raw_input())
for i in range(q):
	a,b=map(int,raw_input().split())
	p=int(np.sqrt(a*b-1))
	r=p*2-1
	if p*p+p>a*b-1:
		r=r-1
	if a==b:
		r=r+1
	print r

Submission status: Wrong Answer

Solution code:
q=int(raw_input())
for i in range(q):
	a,b=map(int,raw_input().split())
	p=int((a*b-1)**0.5)
	r=p*2-1
	if p*p+p>a*b-1:
		r=r-1
	if a==b:
		r=r+1
	print r

Submission status: Wrong Answer

Solution code:
for i in range(input()):
  a,b=map(int,raw_input().split())
  t=int((a*b-1)**0.5)
  print 2*t-1-(t*t+t>a*b-1)+(a==b)

Submission status: Wrong Answer

Solution code:
import numpy as np
def f(a, b):
    t = int(np.sqrt(a*b-1))
    if a == b:
        return 2*t
    if t*(t+1) > a*b-1:
        return 2*t-2
    return 2*t-1
for i in range(input()):
    a, b = map(int, raw_input().split())
    print f(a,b)

Submission status: Wrong Answer

Solution code:
def f(a, b):
    if a > b:
        a, b = b, a
    t = int((a*b-1)**0.5)
    if a == b:
        return 2*t
    if t**2 == a*b-1:
        return 2*t-2
    if t*(t+1) > a*b-1:
        return 2*t-2
    return 2*t-1

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 094 d問題 WA
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
Comment    : 不等式での押さえ込みを意識すること
"""
from math import ceil, sqrt

Q = int(input())
for i in range(Q):
    A, B = sorted(map(int, input().split(" ")))
    s = A*B

    if A == B:
        print(2*A - 2)
    elif A == B + 1:
        print(2*A - 2)
    else:
        C = ceil(sqrt(s)) - 1
        print(2*C - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
for i in range(n):
    arr.append([int(x) for x in input().split()])
for pair in arr:
    first = {}
    first[pair[0]] = pair[0]
    second = {}
    second[pair[1]] = pair[1]
    pairs = []
    _max = max(pair)
    _min = min(pair)
    total = _max * _min - 1
    for i in range(1, total):
        j = int(total / i)
        if i not in first and j not in second:
            first[i] = i
            second[j] = j
            pairs.append([i, j])
    print(len(pairs))

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
for i in range(n):
    arr.append([int(x) for x in input().split()])
for pair in arr:
    first = {}
    first[pair[0]] = pair[0]
    second = {}
    second[pair[1]] = pair[1]
    pairs = []
    _max = max(pair)
    _min = min(pair)
    total = _max * _min
    for i in reversed(range(1, total - 1)):
        for j in range(1, total - 1):
            if i not in first and j not in second and i * j < total:
                first[i] = i
                second[j] = j
                pairs.append([i, j])
    print(len(pairs))

Submission status: Wrong Answer

Solution code:
import math

def count(a, b):
    if a > b:
        a, b = b, a

    if a == b:
        return 2 * (a - 1)

    elif a + 1 == b:
        return 2 * (a - 1)

    else:
        c = int(math.sqrt(a * b - 1e-5))
        if c * (c + 1) > a * b:
            return 2 * c - 2
        else:
            return 2 * c - 1

def D():
    Q = int(input())
    ab = []
    for _ in range(Q):
        ab.append(list(map(int, input().split(' '))))

    for a, b in ab:
        print(count(a, b))

if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
from math import sqrt
Q = int(input())
que = []
for i in range(Q):
    que.append(tuple(map(int, input().split())))
for q in que:
    if q[0] == q[1]:
        print(2*q[0]-2)
    else:
        a = q[0]*q[1]
        p = int(sqrt(a-1))
        if a > p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Wrong Answer

Solution code:
from math import sqrt
Q = int(input())
que = []
for i in range(Q):
    que.append(tuple(map(int, input().split())))
for q in que:
    if q[0] == q[1]:
        print(2*q[0]-2)
    else:
        a = q[0]*q[1]-1
        p = int(sqrt(a))
        if (a+1) > p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Wrong Answer

Solution code:
from math import sqrt
Q = int(input())
que = []
for i in range(Q):
    que.append(tuple(map(int, input().split())))
for q in que:
    if q[0] == q[1]:
        print(2*q[0]-2)
    else:
        a = q[0]*q[1]-1
        p = int(sqrt(a))
        if a > p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Wrong Answer

Solution code:
from math import sqrt
Q = int(input())
que = []
for i in range(Q):
    que.append(tuple(map(int, input().split())))
for q in que:
    if q[0] == q[1]:
        print(2*q[0]-2)
    else:
        a = q[0]*q[1]-1
        p = int(sqrt(a))
        if a+1 > p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Wrong Answer

Solution code:
from math import sqrt
Q = int(input())
que = []
for i in range(Q):
    que.append(list(map(int, input().split())))
for q in que:
    if q[0] > q[1]:
        q[0],q[1] = q[1],q[0]
    if q[0] == q[1]:
        print(2*q[0]-2)
    else:
        a = q[0]*q[1]-1
        p = int(sqrt(a))
        if a+1 > p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Wrong Answer

Solution code:
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))
    c = x * 2
    if x * (x + 1) >= p:
        c -= 1
    if a <= x:
        c -= 1
    if b <= x:
        c -= 1
    print(c)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
for _ in range(n):
    a, b = map(int, input().split())
    num = math.floor((a * b - 1) ** 0.5)
    ans = num * 2
    if num * (num + 1) >= a * b:
        ans -= 1
    if min(a, b) <= num:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False
if debug_mode:
    import os
    infile = open(os.path.basename(__file__).replace(".py", ".in"))

    def input():
        return infile.readline()


# ==============================================================

from math import sqrt


def main():
    Q = int(input().strip())
    AB = [list(map(int, input().strip().split())) for _ in range(Q)]
    for a, b in AB:
        score = a * b
        root = sqrt(score)
        pivot = int(root)
        cnt = 2 * (pivot - 1) if pivot == root else 2 * (pivot - 1) + 1
        print(cnt)


main()

# ==============================================================

if debug_mode:
    infile.close()

Submission status: Wrong Answer

Solution code:
Q = int(input())
for i in range(Q):
    a,b = map(int,input().split())
    if a > b: a,b = b,a
    if b in (a, a+1):
        print((a-1)*2)
        continue
    c = int((a*b)**0.5 - 2**(-30))
    ans = 2*c - 2
    if c*(c+1) < a*b:
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
# import sys
# argv = sys.argv
# with open(argv[1], 'r') as f:
#     stdin = f.read()

Q = int(input().strip('\n'))
A = list()
B = list()
for i in range(Q):
    inDatas = input().strip('\n').split(' ')
    a, b = list(map(int, inDatas))
    score = a*b
    pa = 1
    pb = score
    count = 0
    while pb >= 1:
        if pa == a: pa += 1
        else:
            while pa*pb >= score or pb == b:
                pb -= 1
            count += 1
            pa += 1
            pb -= 1
    print(count)