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

q=int(raw_input())
l=[]
for i in xrange(q):
 a,b=map(int,raw_input().split())
 if a*b<3:
  l.append(0)
 else:
  l.append(int(math.sqrt(a*b))*2-1)
for i in xrange(q):
 print l[i]

Submission status: Wrong Answer

Solution code:
#abc093d
import math

q=int(raw_input())
for i in xrange(q):
 a,b=map(int,raw_input().split())
 if a*b<3:
  print 0
 else:
  res=int(math.sqrt(a*b))*2-1
  print res

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)
    elif q[0]+1 == 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)
    elif q[0]+1 == 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(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)
    elif q[0]+1 == 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(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)
    elif q[0]+1 == q[1]:
        print(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 >= p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

INC, DEC = range(2)

def get_max_val(inc, dec, count):
    if count == 0:
        return 0
    # ((inc + i) * (dec - i))' = 0 is the max_index
    max_index = (dec - inc) / 2.0
    low, high = 0, count - 1
    max_val = -1

    below = int(floor(max_index))
    above = int(ceil(max_index))

    for elem in (below, above):
        if 0 <= elem and elem <= count - 1:
            max_val = max(
                max_val,
                (inc + elem) * (dec - elem))
        elif elem < 0:
            max_val = max(
                max_val,
                inc * dec)
        else: # elem > count - 1
            max_val = max(
                max_val,
                (inc + count - 1) * (dec - count + 1))

    return max_val


def solve(a, b):
    if max(a, b) <= 2 and min(a, b) == 1:
        return 0
    limit = a * b - 1

    low, high = 1, limit + 1
    while high - low > 1:
        mid = (low + high) / 2
        max_val = -1
        missing = []
        if mid >= b:
            missing.append((mid - b, DEC))
        if mid >= a:
            missing.append((a - 1, INC))

        inc = 1
        dec = mid + 1 if mid >= b else mid
        curr_index = 0
        for index, typ in sorted(missing):
            if index != 0:
                length = index - 1 - curr_index + 1
                max_val = max(
                    max_val,
                    get_max_val(inc, dec, length))
            else:
                length = 0
            curr_index = index
            if typ == INC:
                inc += length + 1
                dec -= length
            else:
                inc += length
                dec -= length + 1

        length = mid - 1 - curr_index + 1

        max_val = max(
            max_val,
            get_max_val(inc, dec, length))

        if max_val > limit:
            high = mid
        else:
            low = mid

    return low

q = int(raw_input().strip())
for _ in xrange(q):
    a, b = map(int, raw_input().strip().split())
    print solve(a, b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

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

Submission status: Wrong Answer

Solution code:
import math

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

for i in grid:
  i.sort()
  a,b = [i[0],i[1]]
  if(a == b or a+1 == b):
    print(2*a-2)
  else:
    c = int(math.sqrt(a*b-1))
    # print("here")
    # print(c)
    if(c*(c+1)>=a*b):
      print(2*c-2)
    else:
      print(2*c-1)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N = get_next_int()
    A, B = [], []
    diff_progression = False
    min_B = float('INF')
    for i in range(N):
        a, b = get_next_ints()
        A.append(a)
        B.append(b)
        if a != b:
            diff_progression = True
        if a > b:
            min_B = min(min_B, b)
    if not diff_progression:
        print(0)
    else:
        ans = sum(A) - min_B
        print(ans)

solve()

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

    # As = [1]
    # Bs = [4]

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
Q = int(input())

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

    c = 1
    while True:
        if c ** 2 > A * B:
            c -= 1
            break
        else:
            c += 1
            
    if A == B or A + 1 == B:
        ans = 2 * A - 2
    elif c * (c + 1) >= A * B:
        ans = 2 * c - 2
    elif c ** 2 < A * B:
        ans = 2 * c - 1

    print(ans)

Submission status: Wrong Answer

Solution code:
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    print(last)
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Submission status: Wrong Answer

Solution code:
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Submission status: Wrong Answer

Solution code:
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = (M * m) ** 0.5
    if last % 1 != 0:
        last = int(last)
    else:
        last -= 1
        last = int(last)
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Submission status: Wrong Answer

Solution code:
import math

text = input()

q = int(text)

array = []

for i in range(q):
    text = input()
    a = int(text.split(' ')[0])
    b = int(text.split(' ')[1])
    # array.append([a, b])

    m = a * b
    x, y = sorted([a, b])

    r = int(math.sqrt(m-1))
    cnt = r * 2

    if x <= r:
        cnt-=1

    if r * (r + 1) >= m:
        cnt-=1

    print(cnt)

# for i in range(q):
#     a, b = array[i]
#     m = a * b
#     x, y = sorted([a, b])
#
#     r = int(math.sqrt(m-1))
#     cnt = r * 2
#
#     if x <= r:
#         cnt-=1
#
#     if r * (r + 1) >= m:
#         cnt-=1
#
#     print(cnt)

Submission status: Wrong Answer

Solution code:
Q = int(input())

while Q:
    Q -= 1
    from math import sqrt
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Submission status: Wrong Answer

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

def qd_func(a, b):
    if max(a, b) == 1:
        return 0
    import math
    center= int(math.sqrt(a * b))
    takahashi = a * b
    c, d = [1, takahashi-1]
    ans = 0

    if (center+1) * center >= takahashi:
        if center ** 2 == takahashi:
            return (center - 1) * 2 + 1 - 1 - 1
        else:
            return (center-1) * 2 + 1 - 1

    if (center+1) * center < takahashi:
        return center * 2 - 1

for i in range(q):
    print(qd_func(data[i][0], data[i][1]))

Submission status: Wrong Answer

Solution code:
import math

text = input()

q = int(text)

array = []

for i in range(q):
    text = input()
    a = int(text.split(' ')[0])
    b = int(text.split(' ')[1])
    array.append([a, b])

for i in range(q):
    a, b = array[i]
    m = a * b
    x, y = sorted([a, b])

    r = int(math.sqrt(m-1))
    cnt = r * 2

    if r * (r + 1) >= m:
        if x <= r:
            cnt-=2
    else:
        if x <= r:
            cnt-=1

    print(cnt)

Submission status: Wrong Answer

Solution code:
def d_worst_case(Q, R):
    import math
    ans = []
    for a, b in R:
        a, b = min(a, b), max(a, b)
        if a == b:
            ans.append(str(2 * a - 2))
        elif a + 1 == b:
            ans.append(str(2 * a - 2))
        else:
            c = math.floor(math.sqrt(a * b - 10**(-6)))
            if c * (c + 1) >= a * b:
                ans.append(str(2 * c - 2))
            else:
                ans.append(str(2 * c - 1))
    return '\n'.join(ans)

Q = int(input())
R = [[int(i) for i in input().split()] for j in range(Q)]
print(d_worst_case(Q, R))

Submission status: Wrong Answer

Solution code:
import math
q = int(input())
a = []
b = []
for i in range(q):
  ta, tb = map(int, input().split())
  a.append(ta)
  b.append(tb)

for i in range(q):
  target = a[i]*b[i]-1
  x = int(math.sqrt(target))
  if x == 0:
    print(0)
  else:
    print(2*x - 1 - (x == target//x) + (a[i] == b[i]))

Submission status: Wrong Answer

Solution code:
import math

text = input()

q = int(text)

array = []

for i in range(q):
    text = input()
    a = int(text.split(' ')[0])
    b = int(text.split(' ')[1])
    array.append([a, b])

for i in range(q):
    a, b = array[i]
    m = a * b
    x, y = sorted([a, b])

    r = int(math.sqrt(m-1))
    cnt = r * 2

    if r * (r + 1) >= m:
        if x <= r:
            cnt-=2
        else:
            cnt-=1
    else:
        if x <= r:
            cnt-=1
        if y <= r:
            cnt-=1

    print(cnt)

Submission status: Wrong Answer

Solution code:
import math

text = input()

q = int(text)

array = []

for i in range(q):
    text = input()
    a = int(text.split(' ')[0])
    b = int(text.split(' ')[1])
    array.append([a, b])

for i in range(q):
    a, b = array[i]
    m = a * b
    x, y = sorted([a, b])

    r = int(math.sqrt(m-1))
    cnt = r * 2
    if x <= r:
        cnt-=1
    if y <= r:
        cnt-=1
    if r * (r + 1) >= m:
        cnt-=1

    print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

text = input()

q = int(text)

array = []

for i in range(q):
    text = input()
    a = int(text.split(' ')[0])
    b = int(text.split(' ')[1])
    array.append([a, b])

for i in range(q):
    a, b = array[i]
    m = a * b
    x, y = sorted([a, b])

    r = int(math.sqrt(m-1))
    cnt = r * 2
    if r * (r + 1) >= m:
        cnt-=2
    elif x <= r:
        cnt-=1

    print(cnt)

Submission status: Wrong Answer

Solution code:
import math

text = input()

q = int(text)

array = []

for i in range(q):
    text = input()
    a = int(text.split(' ')[0])
    b = int(text.split(' ')[1])
    array.append([a, b])

for i in range(q):
    a, b = array[i]
    m = a * b
    x, y = sorted([a, b])

    r = int(math.sqrt(m-1))
    cnt = r * 2
    if x <= r:
        cnt-=1
    if r * (r + 1) >= m:
        cnt-=1

    print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = int(buf)
  if buf == x[0]*x[1]:
    buf -= 1

  ans = buf * 2 - 2
  if buf*(buf+1) < x[0]*x[1]:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1]:
    print 2*x[0] - 2
    continue

  if x[0]+1 == x[1]:
    print 2*x[0] - 2
    continue

  q = x[0]*x[1]
  q = int(math.sqrt(q))

  if q*(q+1) >= x[0]*x[1]:
    print 2*q - 2
    continue

  print 2*q - 1

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b - 1))
        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = int(buf)
  if buf == int(q):
    buf -= 1

  ans = buf * 2 - 2
  # Wait! too many removal or not?
  #if int(q-1)/buf > buf:
  if buf*(buf+1) < x[0]*x[1]:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b - 1))
        if c * (c + 1) >= a * b:
            print(2 * floor(sqrt(a * b)) - 2)
        else:
            print(2 * floor(sqrt(a * b)) - 1)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b - 1))
        if c * (c + 1) >= a + b:
            print(2 * floor(sqrt(a * b)) - 2)
        else:
            print(2 * floor(sqrt(a * b)) - 1)

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = int(buf)

  ans = buf * 2 - 2
  # Wait! too many removal or not?
  #if int(q-1)/buf > buf:
  if buf*(buf+1) < x[0]*x[1]:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:

from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        if sqrt(a * b) == floor(sqrt(a * b)):
            print(2 * floor(sqrt(a * b)) - 3)
        else:
            print(2 * floor(sqrt(a * b)) - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
 
q = int(input())
 
a = np.zeros(q, np.int)
b = np.zeros(q, np.int)
 
for i in range(q):
    a[i], b[i] = list(map(int, input().split(" ")))
 
for i in range(q):
    if(a[i] > 1000 or b[i] > 1000): 
        s = np.sqrt(a[i]) * np.sqrt(b[i])
    else:
        s = np.sqrt(a[i] * b[i])
    if(s <= np.sqrt(2)):
        print("0")
    elif(s <= np.sqrt(4)):
        print("1")
    else:
        if(math.floor(s)*(math.floor(s)+1) >= a[i] * b[i]):
            print(int(math.floor(s))*2-2)
        else:
            print(int(math.floor(s))*2-1)

Submission status: Wrong Answer

Solution code:
q = int(input())
countq = 0
while countq < q:
    countq += 1

    s=input().split()
    a = int(s[0])
    b = int(s[1])

    tempa = [a]
    tempb = [b]

    for ai in range(1,a*b+1):
        if ai in tempa:
            continue
        bi = int(a*b/ai)
        while (bi in tempb) or (ai * bi >= a*b ):
            bi -= 1
        if bi < 1:
            break
        print(ai,bi)
        tempb.append(bi)
        tempa.append(ai)

    print(len(tempa)-1,len(tempb)-1)

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == 1:
    if x[1] < 3:
      print "0"
      continue

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = math.floor(buf)
  buf = int(buf)
  # remove takahashi...
  ans = buf * 2 - 2
  # print ans, int(q-1)/buf, buf
  # Wait! too many removal or not?
  #if int(q-1)/buf > buf:
  if buf*(buf+1) < x[0]*x[1]:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:
import sys
import math

Q=int(input())
l=[]
for i in range(Q):
	l.append(list(map(int,input().split())))

for item in l:

	score=item[0]*item[1]

	if(score>100):
		i=math.ceil(math.sqrt(item[0]*item[1])-1)

		count=i*2
		if i>min(item):
			count-=1
		if i>max(item):
			count-=1
		print(count)
	else:

		count=0
		a=[]
		b=[]
		a.append(item[0])
		b.append(item[1])
		
		i=score-1
		hoge=1
		while i>0:
			if hoge in a or hoge in b:
				i=int(score/(hoge+1))+1
				hoge+=1
			j=1
			while i*j<score:

				if(i not in a) and (j not in b):
					count+=1
					a.append(i)
					b.append(j)
					if i not in b and j not in a:
						count+=1
						a.append(j)
						b.append(i)
					#print(i)
					#print(j)
					#print("-----")
				j+=1
			i-=1
		print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == 1:
    if x[1] < 3:
      print "0"
      continue

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = math.floor(buf)
  buf = int(buf)
  # remove takahashi...
  ans = buf * 2 - 2
  # print ans, int(q-1)/buf, buf
  # Wait! too many removal or not?
  #if int(q-1)/buf > buf:
  if buf*buf < x[0]*x[1]:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == 1:
    if x[1] < 3:
      print "0"
      continue

  if x[0] == x[1] or x[0] == (x[1]-1):
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = math.floor(buf)
  buf = int(buf)
  # remove takahashi...
  ans = buf * 2 - 2
  # print ans, int(q-1)/buf, buf
  # Wait! too many removal or not?
  if int(q-1)/buf > buf:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == 1:
    if x[1] < 3:
      print "0"
      continue

  if x[0] == x[1]:
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = math.floor(buf)
  buf = int(buf)
  # remove takahashi...
  ans = buf * 2 - 2
  # print ans, int(q-1)/buf, buf
  # Wait! too many removal or not?
  if int(q-1)/buf > buf:
    ans += 1

  print ans

Submission status: Wrong Answer

Solution code:
import sys
import math

Q=int(input())
l=[]
for i in range(Q):
	l.append(list(map(int,input().split())))

for item in l:

	score=item[0]*item[1]
	if(score>100):
		i=int(math.sqrt(item[0]*item[1]))
		count=i*2
		if i>min(item):
			count-=1
		if i>max(item):
			count-=1
		print(count)
	else:

		count=0
		a=[]
		b=[]
		a.append(item[0])
		b.append(item[1])
		
		i=score-1
		hoge=1
		while i>0:
			if hoge in a or hoge in b:
				i=int(score/(hoge+1))+1
				hoge+=1
			j=1
			while i*j<score:

				if(i not in a) and (j not in b):
					count+=1
					a.append(i)
					b.append(j)
					if i not in b and j not in a:
						count+=1
						a.append(j)
						b.append(i)
					#print(i)
					#print(j)
					#print("-----")
				j+=1
			i-=1
		print(count)

Submission status: Wrong Answer

Solution code:
import sys
import math

Q=int(input())
l=[]
for i in range(Q):
	l.append(list(map(int,input().split())))

for item in l:

	score=item[0]*item[1]
	if(score>100):
		i=int(math.sqrt(item[0]*item[1]))
		count=i*2
		if i>min(item):
			count-=1
		if i>max(item):
			count-=1
		print(count)
	else:

		count=0
		a=[]
		b=[]
		a.append(item[0])
		b.append(item[1])
		
		i=score-1
		hoge=1
		while i>0:
			if hoge in a or hoge in b:
				i=int(score/(hoge+1))+1
				hoge+=1
			j=1
			while i*j<score:

				if(i not in a) and (j not in b):
					count+=1
					a.append(i)
					b.append(j)
					if i not in b and j not in a:
						count+=1
						a.append(j)
						b.append(i)
					print(i)
					print(j)
					print("-----")
				j+=1
			i-=1
		print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == 1:
    if x[1] < 3:
      print "0"
      continue

  if x[0] == x[1]:
    print (x[0]-1)*2
    continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = math.floor(buf)
  buf = int(buf)
  # remove takahashi...
  ans = buf * 2 - 2
  # print ans, int(q-1)/buf, buf
  # Wait! too many removal or not?
  if int(q-1)/buf > buf:
    ans += 1
  elif buf == int(math.sqrt(x[0]*x[1])):
    ans -= 1
  print ans

Submission status: Wrong Answer

Solution code:
import sys
import math

Q=int(input())
l=[]
for i in range(Q):
	l.append(list(map(int,input().split())))

for item in l:

	score=item[0]*item[1]
	i=int(math.sqrt(item[0]*item[1]))
	count=i*2
	if i>min(item):
		count-=1
	if i>max(item):
		count-=1
	print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

for a in range(n):
  x = map(int,raw_input().split())
  x.sort()

  if x[0] == 1:
    if x[1] < 3:
      print "0"
      continue

  q = x[0]*x[1]
  q = float(q)
  buf = math.sqrt(q)
  buf = math.floor(buf)
  buf = int(buf)
  # remove takahashi...
  ans = buf * 2 - 2
  # print ans, int(q-1)/buf, buf
  # Wait! too many removal or not?
  if int(q-1)/buf > buf and x[0] != 1:
    ans += 1
  if buf == math.sqrt(x[0]*x[1]):
    ans -= 1
  print ans

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    A, B = inpl()
    if A==B:
        ans = (A*2-1)-1
    elif abs(A-B)==1:
        ans = min(A, B)*2-2
    else:
        if int((A*B-1)**(1/2))==(A*B-1)**(1/2):
            ans = int((A*B-1)**(1/2))*2-1-1
        else:
            ans = int((A*B-1)**(1/2))*2-1
        
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt, ceil
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    ma = a*b - 1
    mi = ma + 1
    i = int(sqrt(ma))
    while(True):
        i += 1
        t = ceil(ma / i) - 1
        if t < mi:
            mi = t
        else:
            break
    if a == b == 1:
        print(0)
    if a * b == 3:
        print(1)
    else:
        print(i + mi - (2 if a == b else 3))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())



for n in range(N):
    num = 0
    A, B = map(int, input().split())
    
    route = math.floor((A * B) ** (1/2))

    for i in range(1, route+1):
        j = A * B // i

        if A * B % i != 0:
            if i != A and j != B:
                num += 1
            if i != B and j != A:
                num += 1
            if i == j:
                num -= 1

    print(num)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor

def rank(a, b):
    a, b = max(a,b), min(a,b)
    s = floor(sqrt(a*b))
    r = a*b
    cnt = 0
    for i in range(1,s):
        if i == a or i == b:
            continue
        k = r // i
        r = k
        if (k <= s):
            break
        else:
            cnt += 1
    return cnt * 2

Q = int(input())
for i in range(Q):
    A, B = list(map(int, input().split()))
    print(rank(A, B))

Submission status: Wrong Answer

Solution code:
import math


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def calc_worst(A, B):
    mul = A * B
    root = int(math.sqrt(mul))
    ans = 0
    for i in range(1, root + 1):
        div = int(mul / i)
        if (div == A and i == B) or (i == A or div == B):
            if not A == B:
                ans += 1
            else:
                continue
        elif div == A or div == B or i == A or i == B or i == div:
            ans += 1
        else:
            ans += 2
    return ans


def solve():
    N = get_next_int()
    for i in range(N):
        A, B = get_next_ints()
        print(calc_worst(A, B))

solve()

Submission status: Wrong Answer

Solution code:
Q = int(input())
for n in range(Q):
    li = list(map(int,input().split()))
    x,y = map(int,sorted(li))
    z = x + int((x*y)//(x+1)) - 1
    print(z)

Submission status: Wrong Answer

Solution code:
import math

q=int(input())
numli_list= [list(map(int,input().split())) for i in range (q)]
def f(numli):
    n=numli[0]*numli[1]-1
    if numli[0] == numli[1]:
        s = 1
    else:
        s = 0
    return int(math.sqrt(n))+n//(int(math.sqrt(n))+1)-1+s

for i in range (q):
    print(f(numli_list[i]))

Submission status: Wrong Answer

Solution code:
import math
Q = int(input())
for i in range(Q):
    a, b = map(int, input().split())
    score = a * b
    root_score = math.sqrt(score)
    if root_score == int(root_score):
        print(int((root_score -1) * 2))
    else:
        print(int((root_score -1) * 2))