You are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something.

More precisely, you want to spam the emote triangle of size $k$. It consists of $2k-1$ messages. The first message consists of one emote, the second one — of two emotes, ..., the $k$-th one — of $k$ emotes, the $k+1$-th one — of $k-1$ emotes, ..., and the last one — of one emote.

For example, the emote triangle for $k=3$ consists of $5$ messages:

Of course, most of the channels have auto moderation. Auto moderator of the current chat will ban you right after you spam at least $x$ emotes in succession (you can assume you are the only user in the chat). Now you are interested — how many messages will you write before getting banned? Or maybe you will not get banned at all (i.e. will write all $2k-1$ messages and complete your emote triangle successfully)? Note that if you get banned as a result of writing a message, this message is also counted.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The next $t$ lines describe test cases.

The only line of the test case contains integers $k$ and $x$ ($1 \le k \le 10^9; 1 \le x \le 10^{18}$).


-----Output-----

For each test case, print the number of messages you will write before getting banned for the corresponding values $k$ and $x$.


-----Examples-----

Input
7
4 6
4 7
1 2
3 7
2 5
100 1
1000000000 923456789987654321
Output
3
4
1
4
3
1
1608737403


-----Note-----

Let's analyze the test cases of the example.

In the first test case, you write three messages containing $1$, $2$ and $3$ emotes respectively, and since $1 + 2 + 3 \ge 6$, you get banned after that.

In the second test case, you write four messages containing $1$, $2$, $3$ and $4$ emotes respectively, and since $1 + 2 + 3 + 4 \ge 7$, you get banned after that.

In the third test case, you write one message containing exactly $1$ emote. It doesn't get you banned, since $1 < 2$, but you have already finished posting your emote triangle. So you wrote one message successfully.

In the fourth test case, you write four messages containing $1$, $2$, $3$ and $2$ emotes respectively, and since $1 + 2 + 3 + 2 \ge 7$, you get banned after that.

In the fifth test case, you write three messages containing $1$, $2$ and $1$ emote respectively. It doesn't get you banned, since $1 + 2 + 1 < 5$, but you have already finished posting your emote triangle. So you wrote three messages successfully.

In the sixth test case, since $x = 1$, you get banned as soon as you send your first message.

The seventh test case is too large to analyze, so we'll skip it.

Difficulty: EASY
Tags: Sorting

Mathematics
Skill types: Sorting

Starter code:

Solutions:
import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(K, X) = map(int, input().split())
	a = K * (K + 1) // 2
	if X <= a:
		b = int((2 * X) ** 0.5)
		ans = b
		if b * (b + 1) < X * 2:
			ans += 1
		print(ans)
	elif X >= a + a - K:
		print(K + K - 1)
	else:
		X = a + a - K - X
		b = int((2 * X) ** 0.5)
		ans = K + K - 1 - b
		if b * (b + 1) > 2 * X:
			ans += 1
		print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	k = a * (a + 1) // 2
	if b >= 2 * k - a:
		print(2 * a - 1)
	elif b <= k:
		c = int((-1 + (1 + 8 * b) ** (1 / 2)) // 2)
		if c * (c + 1) // 2 >= b:
			print(c)
		else:
			print(c + 1)
	else:
		b = b - a * (a + 1) // 2
		b = a * (a - 1) // 2 - b
		c = int((-1 + (1 + 8 * b) ** (1 / 2)) // 2)
		if c * (c + 1) // 2 <= b:
			print(2 * a - c - 1)
		else:
			print(2 * a - c)


from math import sqrt
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if 2 * x <= k * (k + 1):
		xd = int(sqrt(2 * x))
		while xd * (xd + 1) < 2 * x:
			xd += 1
		print(xd)
	elif x >= k ** 2:
		print(2 * k - 1)
	else:
		ans = k
		temp = k
		x -= k * (k + 1) // 2
		xd = k - int(sqrt(k ** 2 - k - 2 * x)) - 1
		while xd * (2 * k - xd - 1) // 2 < x:
			xd += 1
		ans += xd
		print(ans)


import itertools
from math import floor, log, log2, ceil, sqrt
from itertools import groupby
from decimal import Decimal, getcontext
import sys
t = int(input())
res = []
for i in range(t):
	[k, x] = list(map(int, input().split()))
	ans = 0
	half = k * (k + 1) // 2
	if x >= k ** 2:
		ans = 2 * k - 1
	elif x == half:
		ans = k
	elif x < half:
		ans = ceil((Decimal(1 + 8 * x).sqrt() - 1) / 2)
	else:
		ans = 2 * k - floor((Decimal(1 + 8 * (k ** 2 - x)).sqrt() + 1) / 2)
	res.append(ans)
for i in range(t):
	print(res[i])


for _ in range(int(input())):
	(k, x) = map(int, input().split())
	ans = 0
	t = k * (k + 1) // 2
	if t <= x:
		ans += k
		x -= t
	else:
		y = int((2 * x) ** 0.5)
		ans += y
		x -= y * (y + 1) // 2
		while x > 0:
			ans += 1
			y += 1
			x -= y
		x = 0
	if x:
		t = k * (k - 1) // 2
		if t <= x:
			ans += k - 1
		else:
			p = k * (k - 1) - 2 * x
			y = k - int(p ** 0.5) - 1
			p = t - (k - y) * (k - y - 1) // 2
			ans += y
			x -= p
			y += 1
			while x > 0:
				ans += 1
				x -= k - y
				y += 1
	print(ans)


import math as mt
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b >= a ** 2:
		print(2 * a - 1)
		continue
	x = mt.ceil((-1 + 2 * mt.sqrt(2 * b)) / 2)
	if x <= a and x * (x + 1) // 2 >= b:
		print(x)
		continue
	if x <= a and x * (x + 1) // 2 < b:
		print(x + 1)
		continue
	z = -2 * a * a + a * (a + 1)
	n = 1 - 4 * a
	y = mt.floor((-n - mt.sqrt(n * n - 8 * b + 8 * z)) / 2)
	if 2 * a * y - y * (y + 1) // 2 + a * (a + 1) - 2 * a * a >= b:
		print(y)
		continue
	print(y + 1)


def findline(k, x):
	if k == 1:
		return 1
	if x == 1:
		return 1
	if x > k ** 2:
		return 2 * k - 1
	if x <= k * (k + 1) / 2:
		t = int(((1 + 8 * x) ** 0.5 - 1) / 2)
		if 2 * x <= (t - 1) * t:
			return t - 1
		if 2 * x > t * (t + 1):
			return t + 1
		return t
	t = int((2 * k - 1 - (8 * k ** 2 + 1 - 8 * x) ** 0.5) / 2)
	y = x - t * k
	if y <= (k - t) * (k + t - 1) / 2:
		return t - 1 + k
	if y > k + (k - t - 1) * (k + t) / 2:
		return t + 1 + k
	return t + k
total = int(input())
for i in range(total):
	line = input().split()
	k = int(line[0])
	x = int(line[1])
	print(findline(k, x))


import math

def chat_ban(k, x):
	if x >= k * k:
		return 2 * k - 1
	if x <= k * (k + 1) // 2:
		m = int(math.ceil((-1 + (1 + 8 * x) ** 0.5) / 2))
		for m_ in range(m - 2, m + 3):
			if m_ * (m_ + 1) // 2 < x:
				continue
			return m_
	r = k * k - x
	p = int(math.floor((-1 + (1 + 8 * r) ** 0.5) / 2))
	for p_ in range(p + 3, p - 3, -1):
		if p_ * (p_ + 1) // 2 > r:
			continue
		return 2 * k - p_ - 1
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	print(chat_ban(k, x))


import sys
import math
from fractions import Fraction
from decimal import *
input = sys.stdin.readline
t = int(input())
while t > 0:
	inp = input().strip()
	s = [int(x) for x in inp.split(' ')]
	k = s[0]
	x = s[1]
	if x >= int(k * (k + 1) >> 1) + int(k * (k - 1) >> 1):
		print(2 * k - 1)
	elif x <= int(k * (k + 1) >> 1):
		a = math.ceil(Decimal(8 * x + 1).sqrt() - 1)
		l = math.ceil(a >> 1)
		if a % 2 == 1:
			l += 1
		print(l)
	else:
		l = k
		rem = x - int(k * (k + 1) >> 1)
		notp = int(k * (k - 1) >> 1) - rem
		l += k - 1 - (int(Decimal(8 * notp + 1).sqrt() - 1) >> 1)
		print(l)
	t -= 1


import math
t = int(input())
for i in range(t):
	(k, x) = map(int, input().split())
	s1 = k * (k + 1) // 2
	s2 = s1 - k
	s = s1 + s2
	d = 1 + 8 * x
	r = int((-1 + math.sqrt(d)) // 2)
	if s <= x:
		print(2 * k - 1)
	elif x < s1:
		d = 1 + 8 * x
		r = int((-1 + math.sqrt(d)) // 2)
		if r * (r + 1) // 2 >= x:
			print(r)
		else:
			print(r + 1)
	else:
		x = x - s1
		x = k * (k - 1) // 2 - x
		r = int((-1 + math.sqrt(1 + 8 * x)) // 2)
		if r * (r + 1) // 2 <= x:
			print(2 * k - r - 1)
		else:
			print(2 * k - r)


import math
from decimal import *

def f(k, x):
	k = Decimal(k)
	x = Decimal(x)
	n = x - k * (k + 1) / 2
	fh = math.ceil(((1 + 8 * x).sqrt() - 1) / 2)
	if k * k <= x:
		return 2 * k - 1
	if fh <= k:
		return fh
	else:
		sh = math.ceil(k - Decimal('0.5') - ((k - Decimal('0.5')) ** 2 - 2 * n).sqrt())
		return sh + k
for (a, b) in map(str.split, [*open(0)][1:]):
	print(f(int(a), int(b)))


import math
from decimal import *

def chatBan(k, n):
	if k * (k + 1) // 2 >= n:
		d = Decimal(1 + 8 * n)
		ans = math.ceil((-1 + d.sqrt()) / 2)
	else:
		if n >= k * (k + 1) // 2 + k * (k - 1) // 2:
			return 2 * k - 1
		m = k ** 2 - n
		d = Decimal(1 + 8 * m)
		ans = math.ceil(2 * k - 1 - (-1 + d.sqrt()) / 2)
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(chatBan(n, k))


from sys import stdin

def solve():
	results = []
	for _ in range(int(stdin.readline().strip())):
		(k, x) = map(int, stdin.readline().strip().split())
		if k * k <= x:
			results.append(2 * k - 1)
			continue
		d = k * (k + 1) // 2
		if d > x and d - x < k:
			results.append(k)
			continue
		ans = -1
		inv = 0
		lo = 1
		hi = k
		if x > k * (k + 1) // 2:
			x = k * k - x
			inv = 1
		while lo <= hi:
			mid = lo + (hi - lo) // 2
			d = mid * (mid + 1) // 2
			if d == x:
				ans = mid
				if inv:
					ans += 1
				break
			if d >= x and d - x < mid:
				ans = mid
				break
			elif d < x:
				lo = mid + 1
			else:
				hi = mid - 1
		if ans != -1 and inv:
			ans = 2 * k - ans
		results.append(ans)
	print('\n'.join(map(str, results)))
solve()


from decimal import Decimal, getcontext
from math import ceil, floor
getcontext().prec = 32
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if x <= k * (k + 1) // 2:
		print(ceil((Decimal(x * 8 + 1).sqrt() - 1) / 2))
	elif x >= k ** 2:
		print(k * 2 - 1)
	else:
		print(k * 2 - 1 - floor((Decimal(k ** 2 * 8 - x * 8 + 1).sqrt() - 1) / 2))


from collections import Counter, deque
import math
from random import randint
from bisect import bisect
import sys
import re
import copy
from decimal import Decimal, getcontext
getcontext().prec = 32
MOD = 1000000007
MAX = sys.maxsize
MIN = -sys.maxsize
prime = []

class get:

	def int():
		return list(map(int, input().split()))

	def str():
		return input().split()

	def float():
		return list(map(float, input().split()))

	def map():
		return map(int, input().split())

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

def isPrime(n):
	if n == 1:
		return False
	for i in range(2, sqrt(n)):
		if n % i == 0:
			return False
	return True

def solve():
	(k, x) = get.map()
	sum_ = k * (k + 1) // 2
	if x >= k ** 2:
		print(2 * k - 1)
		return
	if x == sum_:
		print(k)
	elif x < sum_:
		value = (-1 + Decimal(1 + 8 * x).sqrt()) / 2
		print(math.ceil(value))
	else:
		x = x - sum_
		value = (2 * k - 1 - Decimal((2 * k - 1) ** 2 - 8 * x).sqrt()) / 2
		print(k + math.ceil(value))
for _ in range(int(input())):
	solve()


import sys
input = iter(sys.stdin.read().splitlines()).__next__

def sum1toN(n):
	return n * (n + 1) // 2

def solve(k, x):
	total = sum1toN(k) + sum1toN(k - 1)
	if total < x:
		return 2 * k - 1

	def count(m):
		if m <= k:
			return sum1toN(m)
		else:
			return total - sum1toN(2 * k - 1 - m)
	(lo, hi) = (0, 2 * k - 1)
	res = 0
	while lo <= hi:
		mid = lo + (hi - lo) // 2
		if count(mid) >= x:
			res = mid
			hi = mid - 1
		else:
			lo = mid + 1
	return res
res = []
TC = int(input())
for tc in range(TC):
	(k, x) = map(int, input().split())
	res.append(solve(k, x))
print('\n'.join(map(str, res)))


from sys import stdin, setrecursionlimit
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	t = a * (a + 1) // 2
	if t < b:
		if t + a * (a - 1) // 2 <= b:
			ans = 2 * a - 1
		else:
			b -= t
			x = a * (a - 1) // 2 - b

			def f(l, h, x):
				if h == l:
					return h
				if h == l + 1:
					if h * (h + 1) // 2 <= x:
						return h
					return l
				m = (h + l) // 2
				if m * (m + 1) // 2 == x:
					return m
				elif m * (m + 1) // 2 < x:
					if (m + 1) * (m + 2) // 2 > x:
						return m
					return f(m + 1, h, x)
				else:
					return f(l, m - 1, x)
			anss = f(1, a - 1, x)
			ans = a + a - anss - 1
	else:

		def func(l, h, b):
			if h == l:
				return h
			if h == l + 1:
				if l * (l + 1) // 2 >= b:
					return l
				return h
			m = (h + l) // 2
			if m * (m + 1) // 2 >= b:
				return func(l, m, b)
			else:
				return func(m + 1, h, b)
		ans = func(0, a, b)
	print(ans)


import sys
input = sys.stdin.readline

def read_int_list():
	return list(map(int, input().split()))

def gauss_sum(n):
	return n * (n + 1) // 2

def bin_search(x, n):
	(low, up) = (0, 2 * x - 1)
	while low < up:
		mid = (up - low) // 2 + low
		if mid > x:
			res = x * (x + 1) - x - (x - 1 - mid + x) * (2 * x - mid) // 2
		else:
			res = mid * (mid + 1) // 2
		if res >= n:
			up = mid
		else:
			low = mid + 1
	return up
for _ in range(int(input())):
	print(bin_search(*read_int_list()))


def solve():
	(k, x) = list(map(int, input().split()))
	first_half_sum = int(k * (k + 1) / 2)
	second_half_sum = int(k * (k - 1) / 2)
	total_sum = first_half_sum + second_half_sum
	if x >= total_sum:
		return 2 * k - 1
	elif x <= first_half_sum:
		(left, right) = (1, k)
		while left < right:
			mid = (left + right) // 2
			total = mid * (mid + 1) // 2
			if total >= x:
				right = mid
			else:
				left = mid + 1
		return left
	else:
		x = x - first_half_sum
		(left, right) = (1, k - 1)
		while left < right:
			mid = (left + right) // 2
			if (k - 1 + k - mid) * mid // 2 >= x:
				right = mid
			else:
				left = mid + 1
		return k + left
		return k + (k - right)
for i in range(int(input())):
	print(solve())


from decimal import *
import math
jkl = int(input())
for _ in range(jkl):
	(k, x) = map(int, input().split())
	num1 = Decimal(1 + 8 * x).sqrt()
	n1 = math.ceil((num1 - 1) / 2)
	if n1 <= k:
		ans = n1
	else:
		ans = k
		x -= (k ** 2 + k) // 2
		if x > 0:
			a = k - 1
			a1 = 2 * a + 1
			d2 = a1 ** 2 - 8 * x
			if d2 >= 0:
				num1 = Decimal(d2).sqrt()
				n1 = math.ceil((a1 - num1) / 2)
				if n1 < k - 1:
					ans += n1
				else:
					ans = 2 * k - 1
			else:
				ans = 2 * k - 1
	print(ans)


def binary_search(k, x):
	ans = 0
	l = 1
	r = 2 * k - 1
	total = k * (k + 1) - k
	while l <= r:
		m = (l + r) // 2
		req = 0
		if m > k:
			diff = m - k
			val = k - diff
			req = total - val * (val + 1) // 2
		else:
			req = m * (m - 1) // 2
		if x > req:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans
t = int(input())
for i in range(t):
	(k, x) = map(int, input().split())
	print(binary_search(k, x))


def solve():
	(n, s) = [int(x) for x in input().split()]
	if n == 1:
		print(1)
		return
	checker = n * (n + 1) // 2
	if checker == s:
		print(n)
		return
	elif checker > s:
		lo = 1
		hi = n - 1
		while hi >= lo:
			mid = lo + (hi - lo) // 2
			checker = mid * (mid + 1) // 2
			if checker == s:
				print(mid)
				return
			elif checker > s:
				hi = mid - 1
			else:
				lo = mid + 1
		print(lo)
		return
	elif checker < s:
		toCheck = n * (n + 1) // 2 + n * (n - 1) // 2
		if toCheck <= s:
			print(2 * n - 1)
			return
		else:
			lahatLahat = n * (n + 1) // 2
			lahatLahat += n * (n - 1) // 2
			lo = 1
			hi = n - 1
			while hi >= lo:
				mid = lo + (hi - lo) // 2
				cntCnt = (1 + mid - 1) * (mid - 1) // 2
				cntCnt = lahatLahat - cntCnt
				if cntCnt == s:
					print(n + (n - mid))
					return
				elif cntCnt > s:
					lo = mid + 1
				else:
					hi = mid - 1
			print(n + n - hi)
for i in range(int(input())):
	solve()


def solution_1(k, x):
	if x >= k * k:
		return 2 * k - 1
	sum_ = 0
	for i in range(1, 2 * k):
		sum_ += i if i < k else 2 * k - 1 - i
		if sum_ >= x:
			return i

def solution_2(k, x):
	if x >= k * k:
		return 2 * k - 1
	low = 1
	high = 2 * k - 1
	while low < high:
		mid = (low + high) // 2
		if mid <= k:
			target = mid * (mid + 1) // 2
		else:
			target = k * k - (2 * k - 1 - mid) * (2 * k - mid) // 2
		if target >= x:
			high = mid
		else:
			low = mid + 1
	return low
t = int(input())
for i in range(t):
	terms = input().split(' ')
	res = solution_2(int(terms[0]), int(terms[1]))
	print(res)


def next():
	return input()

def nextInt():
	return int(next())

def nextFloat():
	return float(next())

def nextArray(sep=' ', fct=lambda x: x):
	return [fct(d) for d in next().split(sep)]

def nextIntArray(sep=' '):
	return nextArray(sep, int)

def nextFloatArray(sep=' '):
	return nextArray(sep, float)

def getArray(n, sep=' ', fct=lambda x: x):
	return [nextArray(sep, fct) for _ in range(n)]

def getIntArray(n, sep=' '):
	return getArray(n, sep, int)

def getFloatArray(n, sep=' '):
	return getArray(n, sep, float)

def printList(l):
	print(' '.join(map(str, l)))
INF = float('inf')
N = nextInt()
data = getIntArray(N)

def get_emotes(i, k):
	if i <= k:
		return i * (i + 1) // 2
	else:
		return k ** 2 - (2 * k - 1 - i) * (2 * k - i) // 2

def solve(d):
	(k, x) = d
	if k ** 2 <= x:
		print(2 * k - 1)
	else:
		bmin = 1
		bmax = 2 * k - 1
		while bmin < bmax:
			m = (bmax + bmin) // 2
			if get_emotes(m, k) > x:
				bmax = m
			else:
				bmin = m + 1
		if get_emotes(bmin - 1, k) >= x:
			print(bmin - 1)
		else:
			print(bmin)
for d in data:
	solve(d)


from math import sqrt, ceil
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if x >= k ** 2:
		print(2 * k - 1)
	elif x <= k * (k + 1) // 2:
		(l, r) = (1, k)
		while l < r:
			mid = (l + r) // 2
			if mid * (mid + 1) // 2 >= x:
				r = mid
			else:
				l = mid + 1
		print(l)
	else:
		x -= k * (k + 1) // 2
		(l, r) = (1, k - 1)
		while l < r:
			mid = (l + r) // 2
			if (k - 1 + k - mid) * mid // 2 >= x:
				r = mid
			else:
				l = mid + 1
		print(k + l)


for _ in ' ' * int(input()):
	(k, x) = map(int, input().split())
	m = 2 * k - 1

	def smiles(i):
		if i <= k:
			return i * (i + 1) // 2
		else:
			return k * k - (m - i) * (m - i + 1) // 2

	def search(min_lim, max_lim):
		while max_lim - min_lim > 1:
			test_v = (min_lim + max_lim) // 2
			if smiles(test_v) < x:
				min_lim = test_v
			else:
				max_lim = test_v
		return max_lim
	print(search(0, 2 * k - 1))


for _ in range(int(input())):
	(k, x) = map(int, input().split())
	s = k * (k + 1) // 2
	if x <= s:
		(l, r) = (1, k)
		while l < r:
			n = (l + r) // 2
			if n * (n + 1) // 2 < x:
				l = n + 1
			else:
				r = n
		print(r)
	else:
		x -= s
		(l, r) = (1, k - 1)
		while l < r:
			n = (l + r) // 2
			if n * (2 * k - n - 1) // 2 < x:
				l = n + 1
			else:
				r = n
		print(r + k)


def bs(r, x):
	ans = 1
	l = 1
	while l <= r:
		mid = l + (r - l) // 2
		if mid * (mid + 1) // 2 <= x:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans

def bs1(l, x):
	r = 1
	k = l
	ans = l
	while l >= r:
		mid = r + (l - r) // 2
		if k * (k + 1) // 2 - (mid - 1) * mid // 2 <= x:
			ans = mid
			l = mid - 1
		else:
			r = mid + 1
	return ans
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	cnt = bs(k, x)
	cnt1 = 0
	x -= cnt * (cnt + 1) // 2
	if x > 0:
		if cnt < k:
			cnt += 1
		else:
			cnt1 = bs1(k - 1, x)
			x -= (k - 1) * k // 2 - cnt1 * (cnt1 - 1) // 2
			if x > 0 and cnt1 > 1:
				cnt1 = k - cnt1
				cnt1 += 1
			else:
				cnt1 = k - cnt1
	print(min(cnt + cnt1, 2 * k - 1))


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	(a, limit) = ari()
	tt = 2 * a - 1
	low = 1
	high = tt
	ans = 0
	while low <= high:
		mid = low + (high - low) // 2
		if mid <= a:
			n = mid * (mid - 1) // 2 + 1
		else:
			n = a * a - (2 * a - mid) * (2 * a - mid + 1) // 2 + 1
		if n <= limit:
			ans = mid
			low = mid + 1
		else:
			high = mid - 1
	print(high)
	return
for _ in range(test_case):
	ans()


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000000 + 7
mod2 = 998244353
for _ in range(I()):
	(k, x) = M()
	s = 0
	l = 0
	r = 2 * k - 1
	while l <= r:
		m = (l + r) // 2
		if m <= k:
			t = m * (m + 1) // 2
		else:
			p = 2 * k - 1 - m
			t = k * k - p * (p + 1) // 2
		if t > x:
			r = m - 1
		elif t <= x:
			s = m
			l = m + 1
	if s <= k and x > s * (s + 1) // 2 or (s > k and x > k * k - (2 * k - s - 1) * (2 * k - s) // 2):
		print(min(2 * k - 1, s + 1))
	else:
		print(s)


from sys import stdin, stdout
t = int(stdin.readline())
for tt in range(t):
	(k, x) = [int(s) for s in stdin.readline().split()]
	(l, r) = (0, k)
	sm = None
	while l != r:
		n = (l + r) // 2
		sm = n * (n + 1) // 2
		if sm < x:
			l = n + 1
		else:
			r = n
	sm = l * (l + 1) // 2
	if sm >= x:
		print(l)
		continue
	x -= k * (k + 1) // 2
	(l, r) = (0, k - 1)
	sm = None
	while l != r:
		n = (l + r) // 2
		m = k - n
		sm = k * (k - 1) // 2 - m * (m - 1) // 2
		if sm < x:
			l = n + 1
		else:
			r = n
	print(l + k)


import sys
input = sys.stdin.readline

def calc(n):
	return n * (n + 1) // 2
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	lo = 0
	hi = 2 * k - 1
	while lo < hi:
		mi = (lo + hi) // 2
		if mi <= k:
			c = calc(mi)
		else:
			c = calc(k) + (calc(k - 1) - calc(2 * k - 1 - mi))
		if c >= x:
			hi = mi
		else:
			lo = mi + 1
	print(lo)


def calc(a, b):
	if b < a:
		return (1 + b) * b // 2
	else:
		return (a - 1) * a // 2 + (a + a - (b - a)) * (b - a + 1) // 2
t = int(input())
for i in range(t):
	(a, b) = input().split(' ')
	(a, b) = (int(a), int(b))
	ttmp = (1 + a) * a // 2 + (a - 1) * a // 2
	if ttmp < b:
		print(a + a - 1)
		continue
	tmp = (1 + a) * a // 2
	if tmp == b:
		print(a)
	elif tmp > b:
		l = 1
		r = a
		ans = 0
		while l <= r:
			mid = (l + r) // 2
			tmp = (1 + mid) * mid // 2
			if tmp < b:
				l = mid + 1
			elif tmp == b:
				ans = mid
				break
			else:
				r = mid - 1
				ans = mid
		print(ans)
	else:
		l = 1
		r = a
		base = a * (a - 1) // 2
		ans = 10000000
		while l <= r:
			mid = (l + r) // 2
			tmp = base + (a + a - mid + 1) * mid // 2
			if tmp < b:
				l = mid + 1
			elif tmp == b:
				ans = mid
				break
			else:
				r = mid - 1
				ans = mid
		print(ans + a - 1)


def add_messages(start, end, total, x):
	second_half = total * (total + 1) >> 1
	mid = start + end >> 1
	left = total - mid
	messages = second_half - (left * (left + 1) >> 1)
	past = second_half - ((left + 1) * (left + 2) >> 1)
	if past < x <= messages:
		return mid
	elif past >= x:
		return add_messages(start, mid - 1, total, x)
	else:
		return add_messages(mid + 1, end, total, x)

def first_messages(start, end, x):
	mid = start + end >> 1
	messages = mid * (mid + 1) >> 1
	past = mid * (mid - 1) >> 1
	if past < x <= messages:
		return mid
	elif past >= x:
		return first_messages(start, mid - 1, x)
	else:
		return first_messages(mid + 1, end, x)
t = int(input())
for _ in range(t):
	(k, x) = list(map(int, input().split()))
	first_half = k * (k + 1) >> 1
	second_half = k * (k - 1) >> 1
	if first_half + second_half <= x:
		print(int((k << 1) - 1))
	elif first_half <= x:
		print(int(k + add_messages(0, k - 1, k - 1, x - first_half)))
	else:
		print(int(first_messages(0, k, x)))


t = int(input())

def trinum(a, b):
	if a >= b:
		return b * (b + 1) // 2
	else:
		return a * (a + 1) // 2 + (a * (a - 1) // 2 - (2 * a - 1 - b) * (2 * a - 1 - b + 1) // 2)
ret = []
for i in range(t):
	(k, x) = map(int, input().split())
	ok = 0
	ng = 2 * k - 1
	while ng - ok > 1:
		mid = (ok + ng) // 2
		if trinum(k, mid) >= x:
			ng = mid
		else:
			ok = mid
	ret.append(ng)
print(*ret, sep='\n')


for _ in range(int(input())):
	(k, n) = map(int, input().split())
	(l, r) = (0, 2 * k - 1)
	while l < r:
		ans = 0
		mid = (l + r) // 2
		ans = k * (k + 1) - k - (k - 1 - mid + k) * (2 * k - mid) // 2 if mid > k else mid * (mid + 1) // 2
		if ans >= n:
			r = mid
		else:
			l = mid + 1
	print(l)


for t in range(int(input())):
	(k, x) = map(int, input().split())
	l = 0
	r = 2 * k - 1
	if x < k * k:
		while r - l > 1:
			m = l + (r - l) // 2
			if m <= k:
				s = m * (m + 1) // 2
			else:
				s = k * k - (2 * k - 1 - m) * (2 * k - m) // 2
			if s < x:
				l = m
			else:
				r = m
	print(r)


for _ in range(int(input())):
	(k, x) = map(int, input().split())
	(low, high) = (1, 2 * k - 1)
	while low < high:
		mid = (low + high) // 2
		if mid > k:
			v = k * k - (2 * k - 1 - mid) * (2 * k - mid) // 2
		else:
			v = mid * (mid + 1) // 2
		if v < x:
			low = mid + 1
		else:
			high = mid
	print(low)


for _ in range(int(input())):
	(k, x) = map(int, input().split())
	total = k * (k + 1) // 2 + k * (k - 1) // 2
	if x >= total:
		print(2 * k - 1)
	elif x <= k * (k + 1) // 2:
		l = 0
		r = k
		while l < r:
			mid = (l + r) // 2
			if x <= mid * (mid + 1) // 2:
				r = mid
			else:
				l = mid + 1
		print(r)
	else:
		l = 0
		r = k - 1
		while l < r:
			mid = (l + r) // 2
			temp = k - mid
			val = total - temp * (temp - 1) // 2
			if x <= val:
				r = mid
			else:
				l = mid + 1
		print(k + r)


def cal(line, k):
	if line <= k:
		return line * (line + 1) // 2
	else:
		lost_line = k * 2 - 1 - line
		return k * (k + 1) // 2 + (k - 1) * k // 2 - lost_line * (lost_line + 1) // 2

def b_search(k, x):
	(l, r) = (1, 2 * k - 1)
	if cal(r, k) <= x:
		return r
	while l < r:
		mid = (l + r) // 2
		tmp = cal(mid, k)
		if tmp == x:
			return mid
		elif tmp < x:
			l = mid + 1
		else:
			r = mid - 1
	if cal(l, k) >= x:
		return l
	return l + 1
t = int(input())
for i in range(t):
	input_str = list(map(int, input().split()))
	(k, x) = (input_str[0], input_str[1])
	print(b_search(k, x))


for _ in range(int(input())):
	(k, x) = [int(i) for i in input().split()]
	(s, e) = (1, 2 * k - 1)
	result = None
	r = 0
	mid = 0
	while s < e:
		mid = (s + e) // 2
		r = (k - 1 + (2 * k - mid)) * (mid - k) // 2 + k * (k + 1) // 2 if mid > k else mid * (mid + 1) // 2
		if r > x:
			e = mid
		elif r < x:
			s = mid + 1
		else:
			break
	if r < x:
		print(mid + 1)
	else:
		print(mid)


def bin_search(x, k, l, r):
	if abs(l - r) == 0:
		print(l)
		return
	m = l + (r - l) // 2
	if m <= k:
		s = (m + 1) * m // 2
	else:
		n = 2 * k - 1 - m
		s = k ** 2 - (n + 1) * n // 2
	if s >= x:
		bin_search(x, k, l, m)
	else:
		bin_search(x, k, m + 1, r)

def messages():
	n = int(input())
	for _ in range(n):
		line = input()
		(k, x) = line.split(' ')
		k = int(k)
		x = int(x)
		r = 2 * k - 1
		if k ** 2 <= x:
			print(r)
			continue
		bin_search(x, k, 1, r)
messages()


import sys
input = sys.stdin.readline

def solve():
	(k, x) = map(int, input().split())
	(lo, hi) = (1, 2 * k - 1)
	while lo < hi:
		mid = lo + (hi - lo) // 2
		val = min(mid, k) * (min(mid, k) + 1) // 2
		if mid > k:
			val *= 2
			val -= (2 * k - 1 - mid) * (2 * k - mid) // 2 + k
		if val < x:
			lo = mid + 1
		else:
			hi = mid
	return lo
for _ in range(int(input())):
	print(solve())


casos = int(input())
for c in range(casos):
	(N, L) = map(int, input().split())
	if N ** 2 <= L:
		print(2 * N - 1)
	else:
		(ini, fin) = (1, 2 * N - 1)
		exacto = False
		while ini <= fin:
			i = (ini + fin) // 2
			if i <= N:
				cant = i * (i + 1) // 2
				if cant == L:
					print(i)
					exacto = True
					break
				elif cant < L:
					ini = i + 1
				else:
					fin = i - 1
			else:
				cant = i * (i + 1) // 2 - (i - N) * (i - N + 1)
				if cant == L:
					print(i)
					exacto = True
					break
				elif cant < L:
					ini = i + 1
				else:
					fin = i - 1
		if not exacto:
			if cant < L:
				print(i + 1)
			else:
				print(i)


def bsqrt(n):
	assert n >= 0
	if n <= 1:
		return n
	l = 1
	r = n
	while r - l > 1:
		m = (r + l) // 2
		if m * m <= n:
			l = m
		else:
			r = m
	return l

def base_algo(k, x):
	return (bsqrt(8 * x + 1) - 1) // 2
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if x >= k ** 2:
		print(2 * k - 1)
	else:
		q = base_algo(k, x)
		if q <= k and (q + 1) * q // 2 == x:
			print(q)
		elif q < k and (q + 1) * q // 2 != x:
			print(q + 1)
		else:
			print(2 * k - 1 - base_algo(k, k ** 2 - x))


t = int(input())
while t:
	(k, n) = map(int, input().split())
	(l, r) = (0, 2 * k - 1)
	while l < r:
		ans = 0
		mid = (l + r) // 2
		if mid > k:
			ans = k * (k + 1) - k - (k - 1 - mid + k) * (2 * k - mid) // 2
		else:
			ans = mid * (mid + 1) // 2
		if ans >= n:
			r = mid
		else:
			l = mid + 1
	print(l)
	t -= 1


def main():
	n = int(input())
	for i in range(n):
		(k, x) = map(int, input().split(' '))
		if x >= k * k:
			print(2 * k - 1)
			continue
		res = solve(0, 2 * k - 1, x, k)
		print(res)

def solve(low, high, x, k):
	mid = low + (high - low) // 2
	mid_value = calculate_sum(k, mid)
	if high >= low:
		if mid_value > x:
			return solve(low, mid - 1, x, k)
		elif mid_value < x:
			return solve(mid + 1, high, x, k)
		else:
			if mid_value == x:
				return mid
			return mid + 1
	if mid_value == x:
		return mid
	return mid + 1

def calculate_sum(k, index):
	n = 2 * k - 1
	if index <= k:
		return index * (index + 1) // 2
	else:
		return k * k - (n - index) * (n - index + 1) // 2
main()


def totalEmoticons(i, k):
	if i <= k:
		return i * (i + 1) // 2
	else:
		return k * k - (2 * k - 1 - i) * (2 * k - i) // 2

def binarySearch(k, start, end, target):
	mid = (start + end) // 2
	val = totalEmoticons(mid, k)
	if start < end:
		if val < target:
			return binarySearch(k, mid + 1, end, target)
		elif val == target:
			return mid
		else:
			return binarySearch(k, start, mid, target)
	else:
		return start
t = int(input())
for i in range(t):
	[k, x] = [int(num) for num in input().split(' ')]
	if k * (k + 1) <= x:
		print(2 * k - 1)
	else:
		print(binarySearch(k, 1, 2 * k - 1, x))


def solve(k, x):
	tri1 = f(k)
	tri2 = f(k - 1)
	triAll = tri1 + tri2
	if triAll <= x:
		print(2 * k - 1)
		return

	def getchar(x):
		result = 0
		if x > k:
			result = triAll
			result -= f(2 * k - 1 - x)
		else:
			result = f(x)
		return result
	l_mes = 0
	u_mes = 2 * k
	while u_mes - l_mes != 1:
		m_mes = (u_mes + l_mes) // 2
		if getchar(m_mes) >= x:
			u_mes = m_mes
		else:
			l_mes = m_mes
	print(u_mes)

def f(x):
	return (x * x + x) // 2

def main():
	for _ in range(int(input())):
		(k, x) = [int(x) for x in input().split()]
		solve(k, x)
main()


def find_sum(lines, apex):
	x = 0
	if lines > apex:
		x += apex ** 2 + (lines - 2 * apex) * (2 * apex - 1 - lines) // 2
	else:
		x += lines * (lines + 1) // 2
	return x

def binary_search(target, apex):
	(high, low) = (2 * apex - 1, 0)
	while high > low:
		mid = (high + low) // 2
		if find_sum(mid, apex) < target:
			low = mid + 1
		else:
			high = mid
	return low
t = int(input())
for i in range(t):
	(k, x) = [int(i) for i in input().split()]
	print(binary_search(x, k))


for t in range(int(input())):
	(k, x) = map(int, input().split())
	(l, r) = (0, 2 * k - 1)
	while l < r:
		ans = 0
		mid = (l + r) // 2
		if mid > k:
			ans = k * (k + 1) - k - (k - 1 - mid + k) * (2 * k - mid) // 2
		else:
			ans = mid * (mid + 1) // 2
		if ans >= x:
			r = mid
		else:
			l = mid + 1
	print(l)


def S(n):
	return n * (n + 1) // 2
t = int(input())
for i in range(t):
	(k, x) = map(int, input().split())
	if k * k <= x:
		print(2 * k - 1)
		continue
	low = 0
	high = 2 * k
	while low + 1 < high:
		mid = (low + high) // 2
		if mid <= k:
			r = S(mid)
		else:
			r = k * k - S(2 * k - mid - 1)
		if r >= x:
			high = mid
		else:
			low = mid
	if r >= x:
		print(mid)
	else:
		print(mid + 1)


from sys import stdin
input = stdin.readline

def total(k, l):
	if l <= k:
		return l * (l + 1) // 2
	else:
		diff = l - k
		value = k * (k + 1) // 2
		value += k * (k - 1) // 2 - (k - diff) * (k - 1 - diff) // 2
		return value
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if total(k, 2 * k - 1) <= x:
		print(2 * k - 1)
		continue
	(low, high, res) = (0, 2 * k, 0)
	while low < high:
		mid = (low + high) // 2
		if mid == low:
			if total(k, low) >= x:
				res = low
			else:
				res = high
			break
		val = total(k, mid)
		if val == x:
			res = mid
			break
		elif val < x:
			low = mid
		else:
			high = mid
	print(res)


t = int(input())

def cnt(n, m):
	if m < n:
		return m * (m + 1) // 2
	elif m == n:
		return n * (n + 1) // 2
	elif m > n:
		dm = (n - 1) * 2 + 1 - m
		mn = n - 1
		als = mn * (mn + 1) + n
		als -= dm * (dm + 1) // 2
		return als
for i in range(t):
	(n, b) = list(map(int, input().split()))
	l = 0
	r = (n - 1) * 2 + 2
	while r - l > 1:
		m = (r + l) // 2
		am = cnt(n, m)
		if am <= b:
			l = m
		else:
			r = m
	if l == (n - 1) * 2 + 1:
		print(l)
	elif cnt(n, l) < b:
		print(l + 1)
	else:
		print(l)


for tc in range(int(input())):
	(k, x) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	(st, en, top_sum) = (1, k, 0)
	while st <= en:
		mid = (st + en) // 2
		if mid * (mid + 1) <= 2 * x:
			(top_sum, st) = (mid, mid + 1)
		else:
			en = mid - 1
	if top_sum * (top_sum + 1) == 2 * x:
		print(top_sum)
		continue
	elif top_sum < k:
		print(top_sum + 1)
		continue
	else:
		(st, en, ans1) = (1, k - 1, 0)
		rem_x = x - top_sum * (top_sum + 1) // 2
		rem_sum = en * (en + 1) // 2
		while st <= en:
			mid = (st + en) // 2
			mid_sum = mid * (mid + 1) // 2
			if rem_sum - mid_sum >= rem_x:
				st = mid + 1
			else:
				(en, ans1) = (mid - 1, mid)
		print(top_sum + k - ans1)


def find_count(K, y):
	if y <= K:
		return y * (y + 1) // 2
	else:
		return find_count(K, K) * 2 - K - find_count(K, 2 * K - 1 - y)

def lower_bound(K, x):
	low = 0
	high = 2 * K - 1
	while low < high:
		mid = (high + low) // 2
		if find_count(K, mid) < x:
			low = mid + 1
		else:
			high = mid
	print(low)
t = int(input())
for i in range(t):
	s = input().split(' ')
	k = int(s[0])
	x = int(s[1])
	lower_bound(k, x)


for _ in range(int(input())):
	(k, x) = map(int, input().split())
	left = 1
	right = 2 * k - 1
	while left < right:
		mid = (left + right) // 2
		if mid <= k:
			val = mid * (mid + 1) // 2
		else:
			val = k * (k + 1) // 2 + (mid - k) * (3 * k - mid - 1) // 2
		if val < x:
			left = mid + 1
		elif val > x:
			right = mid
		else:
			break
	print((left + right) // 2)


def f(x, k):
	if x <= k:
		return x * (x + 1) // 2
	else:
		x = 2 * k - 1 - x
		return k * (k + 1) // 2 + k * (k - 1) // 2 - x * (x + 1) // 2
t = int(input())
for _ in range(t):
	(k, x) = map(int, input().split())
	l = 0
	r = 2 * k - 1
	while r - l > 1:
		m = (l + r) // 2
		if f(m, k) >= x:
			r = m
		else:
			l = m
	print(r)


t = int(input())
import math

def calc(i, k):
	if i <= k:
		return (1 + i) * i // 2
	return (1 + k) * k // 2 + (k - 1 + (k - (i - k))) * (i - k) // 2
for _ in range(t):
	(k, x) = tuple(map(int, input().split()))
	l = k * k
	if x >= l:
		print(2 * k - 1)
		continue
	res = 0
	l = 1
	h = 2 * k - 1
	while l <= h:
		m = (l + h) // 2
		if calc(m, k) <= x:
			l = m + 1
		else:
			h = m - 1
	x -= calc(h, k)
	if x > 0:
		res += 1
	print(res + h)


def countEmotes(k, row):
	if 1 <= row <= k:
		return row * (row + 1) // 2
	else:
		val = k * (k + 1) // 2
		rem = 2 * k - 1 - row
		val += (k - 1) * k // 2 - rem * (rem + 1) // 2
		return val
test = int(input())
for _ in range(test):
	(k, x) = map(int, input().split())
	(start, end) = (1, 2 * k - 1)
	while start <= end:
		mid = (start + end) // 2
		count = countEmotes(k, mid)
		if count < x:
			start = mid + 1
		else:
			end = mid - 1
	print(min(start, 2 * k - 1))


def good(mid, k, x):
	if mid <= k:
		here = mid * (mid + 1) // 2
		return here >= x
	else:
		here = k * (k + 1) // 2
		left = 2 * k - 1 - mid
		down = k * (k - 1) // 2
		now = down - left * (left + 1) // 2
		return now + here >= x
for _ in range(int(input())):
	(k, x) = map(int, input().split(' '))
	low = 0
	high = 2 * k - 1
	ans = 1
	if good(high, k, x) == False:
		ans = 2 * k - 1
	while low <= high:
		mid = (low + high) // 2
		if good(mid, k, x) == True:
			high = mid - 1
			ans = mid
		else:
			low = mid + 1
	print(ans)


def f(t, k):
	if t <= k:
		return t * (t + 1) // 2
	else:
		a = 2 * k - t - 1
		f = k * k - a * (a + 1) // 2
		return f
for i in range(int(input())):
	(k, x) = map(int, input().split())
	a = 1
	b = 2 * k - 1
	f1 = True
	ans = 0
	while a <= b:
		mid = a + (b - a) // 2
		value = f(mid, k)
		if a == b and value < x and (value < f(mid + 1, k)):
			ans += 1
		if value < x:
			a = mid + 1
		elif value > x:
			b = mid - 1
		elif value == x:
			f1 = False
			break
	print(ans + mid)


for _ in range(int(input())):
	(k, x) = map(int, input().split())
	total = k * k
	low = 1
	high = 2 * k - 1
	ans = 0
	while low <= high:
		mid = (low + high) // 2
		valueTillNow = 0
		if mid > k:
			diff = mid - k
			val = k - diff
			sumOfRightPart = val * (val - 1) // 2
			valueTillNow = total - sumOfRightPart
		else:
			valueTillNow = mid * (mid + 1) // 2
		if valueTillNow < x:
			low = mid + 1
		else:
			ans = mid
			high = mid - 1
	print(max(ans, high))


def get_sum_seq(last_item: int) -> int:
	return last_item * (last_item + 1) // 2
for inn in range(int(input())):
	(k, x) = map(int, input().split())
	(left, right) = (1, 2 * k - 1)
	(middle, answer) = (0, right)
	while left <= right:
		middle = (left + right) // 2
		if middle >= k:
			if 2 * get_sum_seq(k) - k - get_sum_seq(2 * k - middle - 1) >= x:
				answer = middle
				right = middle - 1
			else:
				left = middle + 1
		elif get_sum_seq(middle) >= x:
			answer = middle
			right = middle - 1
		else:
			left = middle + 1
	print(answer)


t = int(input())
for i in range(t):
	(k, x) = map(int, input().split())
	if k * (k + 1) // 2 + k * (k - 1) // 2 < x:
		print(2 * k - 1)
	elif k * (k + 1) // 2 + k * (k - 1) // 2 >= x >= k * (k + 1) // 2:
		l = k
		r = 2 * k - 1
		while r - l > 1:
			mid = (l + r) // 2
			if (k + 1) * k // 2 + k * (mid - k) - (mid - k) * (mid - k + 1) // 2 >= x:
				r = mid
			else:
				l = mid
		mid = l
		if (k + 1) * k // 2 + k * (mid - k) - (mid - k) * (mid - k + 1) // 2 < x:
			mid += 1
		if (k + 1) * k // 2 + k * (mid - k) - (mid - k) * (mid - k + 1) // 2 < x:
			mid += 1
		print(mid)
	else:
		l = 1
		r = k
		while r - l > 1:
			mid = (l + r) // 2
			if mid * (mid + 1) // 2 >= x:
				r = mid
			else:
				l = mid
		mid = l
		if mid * (mid + 1) // 2 < x:
			mid += 1
		if mid * (mid + 1) // 2 < x:
			mid += 1
		print(mid)


def calc(line, size):
	return line * (line + 1) // 2 - max(0, line - size) * (line - size + 1)

def bin_search(emoji_limit, triangle_size):
	lowest_line = 1
	highest_line = 2 * triangle_size - 1
	while highest_line - lowest_line > 1:
		mid_line = (lowest_line + highest_line) // 2
		emoji_printed = calc(mid_line, triangle_size)
		if emoji_printed < emoji_limit:
			lowest_line = mid_line + 1
		else:
			highest_line = mid_line
	if calc(lowest_line, triangle_size) >= emoji_limit:
		return lowest_line
	else:
		return highest_line
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(bin_search(b, a))


def total(n):
	return n * (n + 1) // 2
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if total(k) + total(k - 1) <= x:
		print(2 * k - 1)
	else:
		ch2 = total(k)
		if ch2 > x:
			(l, r) = (0, k)
			while l + 1 < r:
				mid = (l + r) // 2
				if total(mid) < x:
					l = mid
				elif total(mid) > x:
					r = mid
				else:
					r = mid
			print(r)
		elif ch2 < x:
			(l, r) = (0, k)
			while l + 1 < r:
				mid = (l + r) // 2
				if k ** 2 - total(mid + 1) < x:
					r = mid
				elif k ** 2 - total(mid + 1) > x:
					l = mid
				else:
					l = mid
			print(2 * k - r - 1)
		else:
			print(k)


def count(k, lines):
	ret = 0
	start = min(lines, k)
	ret += (start + 1) * start // 2
	if lines > k:
		end = lines - k
		ret += end * k - (end + 1) * end // 2
	return ret

def solve():
	(k, x) = [int(x) for x in input().split()]
	(a, b) = (1, 2 * k - 1)
	while a < b:
		c = (a + b) // 2
		printed = count(k, c)
		if printed < x:
			a = c + 1
		else:
			b = c
	return a
t = int(input())
for _ in range(t):
	print(solve())


for iii in range(int(input())):
	(k, x) = map(int, input().split())
	n = 2 * k
	n -= 1
	low = 0
	high = n
	ans = 0
	while low <= high:
		mid = (low + high) // 2
		summ = 0
		if mid <= k:
			summ = mid * (mid + 1) // 2
		else:
			summ = k * (k + 1) // 2
			xx = mid - k
			summ = summ + xx * (2 * (k - 1) - (xx - 1)) // 2
		if summ == x:
			ans = mid
			break
		if summ < x:
			ans = mid
			low = mid + 1
		else:
			high = mid - 1
	summ = 0
	if ans <= k:
		summ = mid * (mid + 1) // 2
	else:
		summ = k * (k + 1) // 2
		xx = ans - k
		summ = summ + xx * (2 * (k - 1) - (xx - 1)) // 2
	if summ == x:
		print(ans)
	else:
		print(min(ans + 1, n))


def f(a, n):
	return n * (a + a + n - 1) // 2
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	l = 1
	r = 2 * k
	while r - l != 1:
		m = (l + r) // 2
		if m > k:
			a = f(1, k)
			b = f(k - (m - k) + 1, m - k - 1)
			if x > a + b:
				l = m
			else:
				r = m
		else:
			a = f(1, m - 1)
			if x > a:
				l = m
			else:
				r = m
	print(l)


def s(tri, c):
	half = (1 + tri) * tri // 2
	if c == tri:
		return half
	elif c < tri:
		return half - (tri + c + 1) * (tri - c) // 2
	elif c > tri:
		return half + (3 * tri - 1 - c) * (c - tri) // 2

def solve(tri, ban):
	l = 0
	r = 2 * tri - 1
	while l + 1 != r:
		mid = (l + r) // 2
		if s(tri, mid) >= ban:
			r = mid
		else:
			l = mid
	return r
n = int(input())
for i in range(n):
	(triangle, ban) = map(int, input().split())
	print(solve(triangle, ban))


import math

def isPossible(num_emotes, num_lines, k):
	tempcount = 0
	if num_lines <= k:
		tempcount += num_lines * (num_lines - 1) // 2
		tempcount += 1
		if tempcount <= num_emotes:
			return True
		else:
			return False
	elif num_lines > k:
		tempcount += k * k
		templines = 2 * k - 1 - num_lines + 1
		tempcount -= templines * (templines + 1) // 2
		tempcount += 1
		if tempcount <= num_emotes:
			return True
		else:
			return False

def numLinesPossible(k, x):
	if x >= k * k:
		print(2 * k - 1)
		return
	(l, h) = (1, 2 * k - 1)
	ans = -math.inf
	while l <= h:
		m = l + (h - l) // 2
		if isPossible(x, m, k):
			ans = max(ans, m)
			l = m + 1
		else:
			h = m - 1
	print(ans)
	return
t = int(input())
for t in range(1, t + 1):
	arr = [int(j) for j in input().split()]
	(k, x) = (arr[0], arr[1])
	numLinesPossible(k, x)


from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
t = int(input())
for _ in range(t):
	(k, x) = map(int, input().split())
	if k * k <= x:
		print(2 * k - 1)
	else:
		(l, r) = (1, 2 * k - 1)
		while l <= r:
			m = (l + r) // 2
			if m <= k:
				e = m * (m - 1) // 2 + 1
			else:
				e = k * k - (2 * k - m) * (2 * k - m + 1) // 2 + 1
			if e <= x:
				l = m + 1
			else:
				r = m - 1
		print(r)


k = None
mid_sum = None
k_sum = None

def get_sum(num):
	curr_sum = 0
	if num > k:
		return mid_sum + k_sum - get_sum(2 * k - 1 - num)
	else:
		return num * (num + 1) // 2
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	lo = 1
	hi = 2 * k - 1
	mid_sum = k * (k + 1) // 2
	k_sum = k * (k - 1) // 2
	ans = hi
	while lo <= hi:
		mid = (lo + hi) // 2
		curr_sum = get_sum(mid)
		if curr_sum == x:
			ans = mid
			break
		elif curr_sum < x:
			lo = mid + 1
		else:
			ans = mid
			hi = mid - 1
	print(ans)


def check(terms):
	t = min(k, terms)
	max_mess = t * (t + 1) // 2
	if terms > k:
		temp = k * (k - 1) // 2
		ex = k - 1 - terms + t
		temp -= ex * (ex + 1) // 2
		max_mess += temp
	return max_mess < x
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	low = 1
	high = 2 * k - 1
	while low <= high:
		mid = (low + high) // 2
		if check(mid):
			low = mid + 1
		else:
			high = mid - 1
	print(min(low, 2 * k - 1))


t = int(input())
for i in range(t):
	c = 1
	s = 0
	(k, x) = map(int, input().split())
	s1 = k * (k + 1) // 2
	if k == 1:
		print(1)
	elif k * k <= x:
		print(2 * k - 1)
	elif k * (k + 1) // 2 >= x:
		(b, l) = (0, k)
		while b + 1 < l:
			m = int((b + l) // 2 + 0.5)
			if m * (m + 1) // 2 > x:
				l = m
			elif m * (m + 1) // 2 < x:
				b = m
			else:
				print(m)
				break
		else:
			print(l)
	else:
		b = 0
		l = k - 1
		t = l * (l + 1) // 2
		while b + 1 < l:
			m = int((b + l) // 2 + 0.5)
			if t - m * (m + 1) // 2 + s1 < x:
				l = m
			elif t - m * (m + 1) // 2 + s1 > x:
				b = m
			else:
				print(2 * k - m - 1)
				break
		else:
			print(2 * k - l)


import sys
from turtle import end_fill
input = sys.stdin.readline

def solve():
	(k, x) = map(int, input().split())
	(lowest, higest) = (1, 2 * k - 1)
	while lowest < higest:
		mid = lowest + (higest - lowest) // 2
		val = min(mid, k) * (min(mid, k) + 1) // 2
		if mid > k:
			val *= 2
			val -= (2 * k - 1 - mid) * (2 * k - mid) // 2 + k
		if val < x:
			lowest = mid + 1
		else:
			higest = mid
	return lowest
for _ in range(int(input())):
	print(solve())


def get(x):
	return x * (x + 1) // 2
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	l = 1
	r = 2 * k - 1
	res = 2 * k - 1
	over = False
	while l <= r:
		mid = (l + r) // 2
		if mid >= k:
			over = get(k) + get(k - 1) - get(2 * k - 1 - mid) >= x
		else:
			over = get(mid) >= x
		if over:
			res = mid
			r = mid - 1
		else:
			l = mid + 1
	print(res)


def find_sum(k, mid):
	if mid <= k:
		return mid * (mid + 1) // 2
	last = 2 * k - 1
	result = k * (k + 1) // 2
	result += k * (k - 1) // 2 - (last - mid) * (last - mid + 1) // 2
	return result
test = int(input())
for _ in range(test):
	(k, x) = list(map(int, input().strip().split()))
	start = 1
	end = 2 * k - 1
	messages = end
	while start <= end:
		mid = start + (end - start) // 2
		emotes = find_sum(k, mid)
		if emotes < x:
			start = mid + 1
		else:
			messages = mid
			end = mid - 1
	print(messages)


def emote_count(k, m):
	if m <= k:
		return m * (m + 1) // 2
	else:
		return k * (k + 1) // 2 + k * (k - 1) // 2 - (2 * k - 1 - m) * (2 * k - 1 - m + 1) // 2
t = int(input())
while t > 0:
	(k, x) = map(int, input().split())
	if k * k <= x:
		print(2 * k - 1)
	else:
		low = 1
		high = 2 * k - 1
		mid = (low + high) // 2
		msg = 0
		while low <= high:
			mid = (low + high) // 2
			val = emote_count(k, mid)
			if val <= x:
				low = mid + 1
			else:
				msg = mid
				high = mid - 1
		val = emote_count(k, msg)
		if val >= x and emote_count(k, msg - 1) < x:
			print(msg)
		else:
			print(msg - 1)
	t -= 1


def solve(mid, x, k):
	store = min(mid, k)
	ans = store * (store + 1) // 2
	mid -= store
	tem = mid * (2 * (k - 1) + (mid - 1) * -1)
	tem //= 2
	ans += tem
	if ans < x:
		return True
	else:
		return False
import math
for t in range(int(input())):
	(k, x) = map(int, input().split())
	l = 1
	h = 2 * k - 1
	while l < h:
		mid = (l + h) // 2
		if solve(mid, x, k):
			l = mid + 1
		else:
			h = mid
	print(l)


t = int(input())
for i in range(t):
	(k, x) = map(int, input().split())
	left = 1
	right = 2 * k - 1
	total = 2 * k - 1
	mid = left + (right - left) // 2
	while left <= right:
		if mid <= (total + 1) // 2:
			comp = mid * (mid + 1) // 2
			if comp < x:
				left = mid + 1
				mid = left + (right - left) // 2
			else:
				right = mid - 1
				mid = left + (right - left) // 2
		else:
			comp = k * (k + 1) // 2
			dif = mid - k
			comp += (2 * k - 1 - dif) * dif // 2
			if comp < x:
				left = mid + 1
				mid = left + (right - left) // 2
			else:
				right = mid - 1
				mid = left + (right - left) // 2
	if mid <= (total + 1) // 2:
		comp = mid * (mid + 1) // 2
		if comp < x and mid != 2 * k - 1:
			print(mid + 1)
		else:
			print(mid)
	else:
		comp = k * (k + 1) // 2
		dif = mid - k
		comp += (2 * k - 1 - dif) * dif // 2
		if comp < x and mid != 2 * k - 1:
			print(mid + 1)
		else:
			print(mid)


def get(n, k):
	cnt = 2 * k - 1
	l = min(n, k)
	r = max(0, n - l)
	return l * (l + 1) // 2 + r * (cnt - r) // 2

def solve():
	(k, x) = map(int, input().split())
	(l, r) = (0, 2 * k)
	while r > l + 1:
		mid = (l + r) // 2
		if get(mid, k) <= x:
			l = mid
		else:
			r = mid
	ans = l
	if get(l, k) < x:
		ans = r
	print(min(ans, 2 * k - 1))
T = int(input())
for _ in range(T):
	solve()


def ok(k, x, now):
	ans = 0
	ok = min(now, k)
	ans += ok * (ok + 1) // 2
	now -= ok
	a = k - 1
	dec = -1
	n = now
	temp = now * (2 * a + (n - 1) * dec)
	temp = temp // 2
	ans += temp
	if ans < x:
		return 1
	return 0
for i in range(int(input())):
	(n, x) = list(map(int, input().split()))
	l = 1
	h = 2 * n - 1
	while l < h:
		m = (l + h) // 2
		if ok(n, x, m):
			l = m + 1
			continue
		h = m
	print(l)