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:
Q = int(input())
Ri = [list(map(int, input().split())) for _ in range(Q)]

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b

    if a == b:
        print(2 * a - 1)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        r = max_score ** 0.5
        rn = int(r)
        print(2 * rn - 2)

Submission status: Wrong Answer

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

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b
    r = max_score ** 0.5
    rn = int(r)
    ans = int(r * 2 - 2)
    if rn == r and a != b:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

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


max_count = 0
for r in Ri:
    a = r[0]
    b = r[1]
    max_score = a * b
    r1 = pow(max_score, 0.5)
    r2 = int(pow(max_score - 1, 0.5)) * 2 - 2
    r1i = int(r1)
    if r1 - r1i >= 0.5 or r1 == r1i:
        r2 += 1
    if a == b:
        r2 += 1
    print(r2)

Submission status: Wrong Answer

Solution code:
Q = int(input())

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

    if A == B:
        print((A - 1) * (B - 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)

Submission status: Wrong Answer

Solution code:
def upper_square(A: int, B: int) -> int:
    """C**2 < A*B を満たす最大の C を求めます。
    """
    l, r = min(A, B), max(A, B)
    while r - l > 1:
        m = (l + r) // 2
        if m * m < A * B:
            l = m
        else:
            r = m
    return l


def query(A: int, B: int) -> int:
    A, B = min(A, B), max(A, B)
    if A == B:
        # (1, 2A-1), ..., (A-1, A+1), (A+1, A-1), ..., (2A-1, 1)
        # が最大。
        return 2 * A - 2
    if B == A + 1:
        # (1, 2A), ..., (A-1, A+2), (A+2, A-1), ..., (2A, 1)
        # が最大。
        return 2 * A - 2

    # C = A
    # while (C + 1) ** 2 < A * B:
    #     C += 1
    C = upper_square(A, B)

    if A * B <= C * (C + 1):
        # (1, A+B−1), ..., (A−1, B+1), (A+1, 2C−A−1), ..., (C, C), ..., (2C−1, 1)
        # が最大。
        return 2 * C - 2

    # (1, A+B−1), ..., (A−1, B+1), (A+1, 2C−A), ..., (C, C+1), (C+1, C), ...,(2C, 1)
    # が最大。
    return 2*C - 1


def worst_case(Q: int, queries: list) -> list:
    return [query(A, B) for A, B in queries]


if __name__ == "__main__":
    Q = int(input())
    queries = [tuple(map(int, input().split())) for _ in range(Q)]
    ans = worst_case(Q, queries)
    print(ans)

Submission status: Wrong Answer

Solution code:
#import random

q=int(input())
A=[]
for i in range(q):
    A.append(list(map(int,input().split())))
    A[i].sort()

#A=[]
#q=10000
#for i in range(q):
#    A.append([random.randint(1,1000000)]*2)
#    A.sort()
#print(A)

for i in range(q):
    a=A[i][0]
    b=A[i][1]
    if a==b :
        ans1=2*(a-1)
    elif a+1==b :
        ans1=2*a-2
    else :
        c=int((a*b-1)**0.5)+2
        while c*c>=a*b :
            c-=1
        #print("c "+str(c))
        if c*(c+1)>=a*b :
            ans1=2*c-2
        else :
            ans1=2*c-1

print(ans1)

Submission status: Wrong Answer

Solution code:
q=int(input())
A=[]
for i in range(q):
    A.append(list(map(int,input().split())))
    A[i].sort()

for i in range(q):
    a=A[i][0]
    b=A[i][1]
    if a==b :
        print(2*(a-1))
    elif a+1==b :
        print(2*a-2)
    else :
        c=int((a*b-1)**0.5)
        c2=c
        for i in [-1,1]:
            if c+i<a*b and c+i+1>=a*b :
                c2=c+i
        c=c2
        if c*(c+1)>=a*b :
            print(2*c-2)
        else :
            print(2*c-1)

Submission status: Wrong Answer

Solution code:
q=int(input())
A=[]
for i in range(q):
    A.append(list(map(int,input().split())))
    A[i].sort()

for i in range(q):
    a=A[i][0]
    b=A[i][1]
    if a==b :
        print(2*(a-1))
    elif a+1==b :
        print(2*a-2)
    else :
        c=int((a*b-1)**0.5)
        if c*(c+1)>=a*b :
            print(2*c-2)
        else :
            print(2*c-1)

Submission status: Wrong Answer

Solution code:

q=int(input())
A=[]
for i in range(q):
    a,b=map(int,input().split())
    c2=a*b-1
    c=c2**0.5
    #print(c)
    if c==int(c):
        ans=(int(c))*2-1
    else :
        ans=(int(c))*2
    if min(a,b)<=c :
        ans-=1
    if max(a,b)==int(c)+1 and (int(c)+2)*int(c)>c2 :
        ans-=1
    A.append(ans)
for i in range(q):
    print(A[i])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
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 - 1))
        if d * (d + 1) < c:
            print(d * 2 - 1)
        else:
            print(d * 2 - 2)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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!=0:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)

Submission status: Wrong Answer

Solution code:
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)
  if (a*b)%(c+1) == 0:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
for _ in [0]*int(input()):
  a,b = map(int,input().split())
  k = math.floor(math.sqrt(4*a*b))
  if k*k == 4*a*b and not a == b:
    k -= 1
  print(k-2)

Submission status: Wrong Answer

Solution code:
import math
for _ in [0]*int(input()):
  a,b = map(int,input().split())
  k = math.floor((4*a*b)**0.5)
  if k*k == 4*a*b and not a == b:
    k -= 1
  print(k-2)

Submission status: Wrong Answer

Solution code:
import math

def miman(x):
    if(x%1==0):
        return int(x-1)
    else:
        return int(x)

def count(x,y):
    a=int((-1+(1+4*x*y)**(0.5))/2)-1
    if(a<=0):
        a=1
    while(miman(x*y/a)!=miman(x*y/(a+1))):
        a+=1
    if(x-1<=a):
        return min( [x-1,miman(x*y/(y+1)) ] )
    else:
        return a-1 + miman(x*y/a) - max( [y,int(x*y/(x-1)) ] )


def judge(x,y):
    a=count(x,y)
    b=count(y,x)
    return a+b+min([x-1-a,y-1-b])

q=int(input())
for i in range(q):
    x,y=map(int,input().split())
    print(judge(x,y))

Submission status: Wrong Answer

Solution code:
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*a - 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))

Submission status: Wrong Answer

Solution code:
def search(a, b):
    if a == b or a + 1 == b:
        return 2 * a - 2
    else:
        c = int((a * b - 1) ** 0.5)
        if c * (c + 1) >= a * b:
            return 2 * c - 2
        else:
            return 2 * c - 1

Q = int(input())
for i in range(Q):
    x = list(map(int, input().split()))
    x.sort()
    print(search(x[0], x[1]))

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())
	C=np.ceil(np.sqrt(A*B))-1
	print int(2*C-2)

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())
	C=np.ceil(np.sqrt(A*B))-1
	print 2*C-2

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())
	C=np.ceil(np.sqrt(A*B))-1
	print C-1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 < 1.5:
        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)

Submission status: Wrong Answer

Solution code:
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 abs(b - a) < 1.5:
        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)

Submission status: Wrong Answer

Solution code:
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 abs(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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 < 2:
        print(2*a - 2)
        
    else:
        if int(sqrt(a*b)) * int(sqrt(a*b)) == 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)

Submission status: Wrong Answer

Solution code:
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 < 2:
        print(2*a - 2)
        
    else:
        if sqrt(a*b) - int(sqrt(a*b)) == 0:
            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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
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 < 2:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = floor(sqrt(a*b) - 1)
        else:
            c  = floor(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
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 (not sqrt(a*b) - int(sqrt(a*b))) and a != b:
        print(floor(2 * sqrt(a*b)) - 3)
    else:
        print(floor(2 * sqrt(a*b)) - 2)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
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:
    print(floor(2 * sqrt(a*b)) - 2)

Submission status: Wrong Answer

Solution code:
#泥臭く場合分けすることが大事


import math

def worst(x, y):
    if x > y:
        return worst(y, x)
    elif x == y:
        return 2 * x - 2
    elif y == x + 1:
        return 2 * x - 2
    else:
        z = int(math.sqrt(x * y - 1))
        if z * (z + 1) < x * y:
            return 2 * z - 1
        else:
            return 2 * z - 2
Q = int(input())
rank = [list(map(int, input().split())) for _ in  range(Q)]

for i in range(Q):
    ai, bi = rank[i]
    print(worst(ai, bi))

Submission status: Wrong Answer

Solution code:
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*(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))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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:
import math

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:
import math

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**2 == seki:
        result -= 1
    if a <= saidai or b <= saidai:
        result -= 1
    print(result)

Submission status: Wrong Answer

Solution code:
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]==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)
    elif score[i][0]==score[i][1]:
        print(2*max_num-2)
    else:
        print(2*max_num-2)

Submission status: Wrong Answer

Solution code:
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]==max_num:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    elif score[i][0]==score[i][1]:
        print(2*max_num-2)
    else:
        print(2*max_num-2)

Submission status: Wrong Answer

Solution code:
from math import floor, sqrt

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

def mysqrt(n):
    x = floor(sqrt(n))
    if (x+1)**2 == n:
        return x+1
    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)

Submission status: Wrong Answer

Solution code:
from math import floor, sqrt

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

def mysqrt(n):
    x = floor(sqrt(n))
    if (x+1)**2 == n:
        return x+1
    return x

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

Submission status: Wrong Answer

Solution code:
from itertools import product
from math import floor, sqrt

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

def mysqrt(n):
    x = floor(sqrt(n))
    if (x+1)**2 == n:
        return x+1
    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)

Submission status: Wrong Answer

Solution code:
from math import floor, sqrt

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

for xy in xys:
    a, b = sorted(xy)
    if b - a < 2:
        print(2*a - 2)
    else:
        ab = a*b
        root = floor(sqrt(ab-1))
        print(root*2 - 2 + ((root + 1) * root < ab))

Submission status: Wrong Answer

Solution code:
from itertools import product
from math import floor, sqrt

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print("\n".join(ans))

Submission status: Wrong Answer

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

print("\n".join(ans))

Submission status: Wrong Answer

Solution code:
Q = int(input())
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    tmp = 2*M - 2
    tmp -= (A < M) or (B < M)
    if A != B and A*B != M*M:
        if M*(M+1) < A*B:
            tmp += 2
        elif M*M < A*B:
            tmp += 1
    print(tmp)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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))
    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]))

Submission status: Wrong Answer

Solution code:
import math

Q = int(input())
for i in range(Q):
    A, B = [int(a) for a in input().split()]
    N = int(math.sqrt(A * B))
    if N ** 2 == A * B:
        N -= 1
    if A*B > N * (N+1):
        print(str(2*N - 1))
    else:
        print(str(2*N - 2))

Submission status: Wrong Answer

Solution code:
import math

Q = int(input())
for i in range(Q):
    A, B = [int(a) for a in input().split()]
    N = int(math.sqrt(A * B))
    if N ** 2 == A * B:
        N -= 1
    if A*B > N * (N+1):
        print(str(2*N))
    else:
        print(str(2*N - 1))

Submission status: Wrong Answer

Solution code:
import math

Q = int(input())
for i in range(Q):
    A, B = [int(a) for a in input().split()]
    N = int(math.sqrt(A * B))
    if N ** 2 == A * B:
        N -= 1
    if A*B > N * (N+1):
        print(str(2*N))
    else:
        print(str(2*N))

Submission status: Wrong Answer

Solution code:
def main():
    Q = int(input())
    A = [0 for _ in range(Q)]
    B = [0 for _ in range(Q)]
    for i in range(Q):
        A[i], B[i] = map(int, input().split())

    for i in range(Q):
        a = min(A[i], B[i])
        b = max(A[i], B[i])
        j = b//(a+1)+1
        count = min(a, j)
        if a>j:
            count += a-j
        count += b-(j+1)
        # v = 1
        # for k in range(b-(j+1),0,-1):
        #     if a*b > k*(a+v):
        #         count += 1
        #         v += 1

        print(count)



if __name__ == '__main__':
    main()

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
    elif t != (a*b-1)/t:
        return 2*t-1
    else:
        return 2*t-2

q = input()
for i in range(q):
    a, b = map(int, raw_input().split())
    print f(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
    elif t**2 != a*b-1:
        return 2*t-1
    else:
        return 2*t-2
q = input()
for i in range(q):
    a, b = map(int, raw_input().split())
    print f(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
    elif t**2 != a*b-1:
        return 2*t-1
    else:
        return 2*t-2
q = input()
res = []
for i in range(q):
    a, b = map(int, raw_input().split())
    res.append(f(a,b))
print "\n".join(map(str, res))

Submission status: Wrong Answer

Solution code:
monndaisuu = input()

for i in range(int(monndaisuu)):
    mondai = input()
    mondai = mondai.rstrip().split(" ")
    m1 =int(mondai[0])
    m2 =int(mondai[1])
    kaisuu = int(m1*m2**(1/2))
    #print(kaisuu)
    if int(m1)*int(m2)<=2:
        print("0")
        i +=1
    elif int(m1)==int(m2):
        print(int((int(m1)-1)*2))
        i +=1
    elif int(m1)==int(m2)+1 or int(m1)==int(m2)-1 :
        if int(m1)>int(m2):
            print(int(int(m2)-1)*2)
        else:
            print(int(int(m1)-1)*2)
    elif (int(m1)*int(m2)-1)**(1/2)%1==0:
        print(int((int(m1)*int(m2)-1)**(1/2)*2)-2)
    else:
        print(int((int(m1)*int(m2)-1)**(1/2))*2-1)

Submission status: Wrong Answer

Solution code:
q=int(input())
a=[0 for i in range(q)]
b=[0 for i in range(q)]
for i in range(q):
    a[i],b[i]=list(map(int,input().split()))
    result=0
    mul=a[i]*b[i]-1
    aa=int(mul**(0.5))
    if (aa+1)**2==mul:
        aa+=1
    result=aa*2
    if aa*(aa+1)>=mul:
        result-=1
    if aa>=a[i]:
        result-=1
    if aa>=b[i]:
        result-=1
    if result<0:
        result=0
    print(result)

Submission status: Wrong Answer

Solution code:
q=int(input())
a=[0 for i in range(q)]
b=[0 for i in range(q)]
for i in range(q):
    a[i],b[i]=list(map(int,input().split()))
    result=0
    mul=a[i]*b[i]-1
    aa=int(mul**(0.5))
    if (aa+1)**2==mul:
        aa+=1
    result=aa*2
    if aa*(aa+1)>mul:
        result-=1
    if aa>=a[i]:
        result-=1
    if aa>=b[i]:
        result-=1
    if result<0:
        result=0
    print(result)

Submission status: Wrong Answer

Solution code:
q=int(input())
a=[0 for i in range(q)]
b=[0 for i in range(q)]
for i in range(q):
    a[i],b[i]=list(map(int,input().split()))
    result=0
    mul=a[i]*b[i]-1
    aa=int(mul**(1/2))
    if (aa+1)**2==mul:
        aa+=1
    result=aa*2
    if aa*(aa+1)>mul:
        result-=1
    if aa>=a[i]:
        result-=1
    if aa>=b[i]:
        result-=1
    print(result)

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

Submission status: Wrong Answer

Solution code:
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=int((a*b-1)**(1/2))
    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))

Submission status: Wrong Answer

Solution code:
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)**(1/2)
    if cnt!=int(cnt):
      return int(cnt)*2-1
    else:
      return int(cnt)*2-2

Q=int(input())

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

Submission status: Wrong Answer

Solution code:
import math
Q = int(input())
inputs = [ list(map(int,input().split())) for i  in range(Q)  ]
 
def nums(a,b):
    ma = max([a,b])
    prod = a * b - 1
    if  prod == 0:
        return 0
    sq = math.floor(math.sqrt(prod))
    ans = 2 * sq
    if prod // sq == sq and sq + 1 != ma:
        ans = ans - 1
    if a != b:
        ans = ans - 1
    return ans
for ab  in inputs:
    print(nums(ab[0],ab[1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
Q = int(input())
inputs = [ list(map(int,input().split())) for i  in range(Q)  ]

def nums(a,b):
    ma = max([a,b])
    prod = a * b - 1
    if  prod == 0:
        return 0
    sq = math.floor(math.sqrt(prod))
    ans = 2 * sq
    if prod // sq == sq:
        ans = ans - 1
    if a != b:
        ans = ans - 1
    return ans
for ab  in inputs:
    print(nums(ab[0],ab[1]))