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

def derive_k(n):#n/k - n/(k+1) >= 1となる最大のkを求める。ただしn>=2
  if n == 1:
    return 0
  lt = 1
  rt = n
  while rt - lt > 1:
    ct = (lt + rt) // 2
    if n >= ct * (ct+1):
      lt = ct
    else:
      rt = ct
  return lt  
  
for _ in range(Q):
  A, B = map(int,input().split())
  k = derive_k(A*B) #A*B/k - A*B/(k+1) >= 1となる最大のkを求める
  ans = k + (A*B-1)//(k+1) - 1
  #print(A, B, k, (A*B-1)//(k+1))
  if k+1 == A:
    ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
q=int(input())
ab=[list(map(int,input().split())) for _ in range(q)]
for a,b in ab:
    if a>b:a,b=b,a
    if a==b:
        print(2*a-2)
    elif a+1==b:
        print(2*a-2)
    else:
        c=int((a*b)**0.5)
        if c*(c+1)>=a*b:
            print(2*c-2)
        elif c**2<a*b:
            print(2*c-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    s=a*b
    m=int(pow(s-1,0.5))
    if m==0:
        ans=0
    elif (s-1)//m==m and (a!=b and abs(a-b)!=1):
        ans=m*2-2
    elif a!=b and abs(a-b)!=1:
        ans=m*2-1
    elif a==b:
        ans=m*2
    else:
        ans=(m-1)*2
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

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


#####Shorten#####
def DD(arg): return defaultdict(arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#############
# Main Code #
#############

def is_ok(x):
  if (score-1)//x > (score-1)//(x+1):
    return True
  else:
    return False

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

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


#####Shorten#####
def DD(arg): return defaultdict(arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#############
# Main Code #
#############

def is_ok(x):
  if (score-1)//x > (score-1)//(x+1):
    return True
  else:
    return False

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

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


#####Shorten#####
def DD(arg): return defaultdict(arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#############
# Main Code #
#############

def is_ok(x):
  if (score-1)//x > (score-1)//(x+1):
    return True
  else:
    return False

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

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


#####Shorten#####
def DD(arg): return defaultdict(arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#############
# Main Code #
#############

def is_ok(x):
  if (score-1)//x > (score-1)//(x+1):
    return True
  else:
    return False

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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


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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt
Q=int(input())
for _ in range(Q):
  A,B=map(int,input().split())
  c=int(sqrt(A*B))
  print(2*c-1)

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    c = a*b
    d = int(c**0.5)
    if a==b:
        print(a*2-2)
    elif a+1 ==b or a == b+1:
        print((min(a,b)-1)*2)
        
    elif d*(d+1) >= c:
        print(d*2-2)
    else:
        print(d*2-1)

Submission status: Wrong Answer

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

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    c = a*b
    d = int((c-1)**0.5)
    if a==b:
        print(a*2-2)
    elif a+1 ==b or a == b+1:
        print((min(a,b)-1)*2)
        
    elif d*(d+1) >= c:
        print(d*2-2)
    else:
        print(d*2-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        ref = a * b - 1
        rng = int(ref ** 0.5)
        res = rng * 2
        if res == 0:
            print(0)
        elif a == b:
            print(2 * a - 2)
        elif ref // rng == rng:
            print(res - 2)
        elif a > rng and b > rng:
            print(res)
        else:
            print(res - 1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

def is_square(P):
    if math.floor(math.sqrt(P))**2==P:
        return math.floor(math.sqrt(P))
    return -1
  
def solve(a, b):
    X = a*b
    X -= 1
    ans = 0
    for i in range(1, X+1):
        if i**2 > X:
            break
        if i != a and X//i != b:
            ans += 1
        if X//i != a and i != b:
            ans += 1
    K=is_square(X)

    if K>0 and K!=a and K!=b:
        ans-=1
    return ans


# 貪欲　とりあえずかんで
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    print(solve(a, b))

Submission status: Wrong Answer

Solution code:
Q = int(input())#100

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

Submission status: Wrong Answer

Solution code:
Q = int(input())#100

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

Submission status: Wrong Answer

Solution code:
Q = int(input())#100

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# C^2 と A*Bの比較
Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1) * 2
    elif b == a+1:
        ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5)
        while (c+1) ** 2 < a*b:
            c += 1
        # c は aより大きい
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# C^2 と A*Bの比較
Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1) * 2
    elif b == a+1:
        ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5 + 0.00001)
        # c は aより大きい
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# C^2 と A*Bの比較
Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1) * 2
    elif b == a+1:
        ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5 + 0.0000001)
        # c は aより大きい
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# C^2 と A*Bの比較
Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1) * 2
    elif b == a+1:
        if a == 1:
            ans = 0
        else:
            ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5)
        # c は aより大きい
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# C^2 と A*Bの比較
Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1)*(b-1)
    elif b == a+1:
        if a == 1:
            ans = 0
        else:
            ans = 2 * (a-1)
    elif b > a + 1:
        c = int((a*b-1) ** .5)
        # c は aより大きい
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# C^2 と A*Bの比較
Q = ir()
answer = []
for _ in range(Q):
    a, b = lr()
    if a > b:
        a, b = b, a
    if a == b:
        ans = (a-1)*(b-1)
    elif b == a+1:
        if a == 1:
            ans = 0
        else:
            ans = b-1
    elif b > a + 1:
        c = int((a*b-1) ** .5)
        # c は aより大きい
        if c * (c+1) >= a * b:
            ans = 2 * c - 2
        else:
            ans = 2 * c - 1
    answer.append(ans)

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