Given a tank with capacity C litres which is completely filled in starting. At the end of every day, tank is filled with L litres of water and in the case of overflow extra water is thrown out. Now on i-th day i litres of water is taken out for drinking. We need to find out the day at which tank will become empty the first time.
Example 1:
Input: C = 5, L = 2
Output: 4 
Explanation: At the start of 1st day, 
water in tank = 5 and at the end of 
the 1st day = (5 - 1) = 4 At the start
of 2nd day, water in tank = 4 + 2 = 6 
but tank capacity is 5 so water = 5 and 
at the end of the 2nd day = (5 - 2) = 3 
At the start of 3rd day, water in 
tank = 3 + 2 = 5 and at the end of the 
3rd day = (5 - 3) = 2 At the start of 4th 
day, water in tank = 2 + 2 = 4 and at the 
end of the 4th day = (4 - 4) = 0 
So final answer will be 4.
Example 2:
Input: C = 6, L = 1
Output: 4
Explanation: At the start of 1st day,
water in tank = 6 and at the end of
the 1st day = (6 - 1) = 5 At the start
of 2nd day, water in tank = 5 + 1 = 6
and at the end of the 2nd day = (5 - 2)= 3
At the start of 3rd day, water in
tank = 3 + 1 = 4 and at the end of the
3rd day = (4 - 3) = 1 At the start of 4th
day, water in tank = 1 + 1 = 2 and at the
end of the 4th day = (2 - 4) < 0
So final answer will be 4.
Your Task:  
You dont need to read input or print anything. Complete the function minDaysToEmpty() which takes C and L as input parameter and returns the the day at which tank will become empty the first time.
Expected Time Complexity: O(logC)
Expected Auxiliary Space: O(1)
Constraints:
1<= C, L <=10^{5}

Difficulty: EASY
Tags: Sorting
Skill types: Sorting
Expected Time Complexity: O(logC)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:

    def minDaysToEmpty (self, c, l):

        # code here 

Solutions:
class Solution:

	def minDaysToEmpty(self, c, l):
		a = c
		count = 1
		while c > 0:
			c = c - count
			if c <= 0:
				break
			else:
				c = c + l
			if c > a:
				c = a
			if c != 0:
				count += 1
		return count


class Solution:

	def minDaysToEmpty(self, c, l):
		C = c
		day = 1
		while True:
			c -= day
			if c <= 0:
				return day
			c += l
			if c > C:
				c = C
			day += 1


class Solution:

	def minDaysToEmpty(self, c, l):
		i = 2

		def counter(i, c, l, current):
			if current <= 0:
				return i - 1
			current = current + l
			if current > c:
				current = c
			return counter(i + 1, c, l, current - i)
		x = counter(i, c, l, c - 1)
		return x


class Solution:

	def minDaysToEmpty(self, c, l):
		tank = c
		i = 1
		while True:
			tank = tank - i
			if tank <= 0:
				return i
			i = i + 1
			tank = tank + l
			if tank > c:
				tank = c


class Solution:

	def minDaysToEmpty(self, c, l):
		tank = c
		day = 0
		while tank > 0:
			day += 1
			tank += l
			tank = min(c, tank)
			tank -= day
		return day


class Solution:

	def minDaysToEmpty(self, c, l):
		wat = c
		i = 0
		while wat > 0:
			i += 1
			wat -= i
			if wat <= 0:
				break
			wat += l
			if wat > c:
				wat = c
		return i


class Solution:

	def minDaysToEmpty(self, c, l):
		cap = c
		count = 0
		for day in range(1, c + 1):
			cap = cap - day
			if cap <= 0:
				count = day
				break
			else:
				cap = cap + l
				if cap > c:
					cap = c
		return count


class Solution:

	def minDaysToEmpty(self, c, l):
		i = 1
		C = c
		d = 0
		while C > 0:
			if C > c:
				C = c
			C = C - i
			i += 1
			d += 1
			if C <= 0:
				return d
			C = C + l
		return d


class Solution:

	def minDaysToEmpty(self, c, l):
		i = l if c > l else c
		ci = c
		while 1:
			cil = ci + l
			cil = c if cil > c else cil
			ci = cil - i
			if ci <= 0:
				return i
			i += 1


class Solution:

	def minDaysToEmpty(self, c, l):
		pani = c
		pani = pani - 1
		i = 2
		while pani > 0:
			pani = pani + l
			if pani >= c:
				pani = c
			pani = pani - i
			i = i + 1
		else:
			return i - 1


import math

class Solution:

	def minDaysToEmpty(self, c, l):
		if l >= c:
			return c
		eq_root = (math.sqrt(1 + 8 * (c - l)) - 1) / 2
		return math.ceil(eq_root) + l


class Solution:

	def csum(self, n):
		return n * (n + 1) // 2

	def binarysearch(self, l, r, L, C):
		if l <= r:
			mid = (l + r) // 2
			w = C - self.csum(mid - (L + 1))
			if w <= mid:
				return self.binarysearch(l, mid - 1, L, C)
			else:
				return self.binarysearch(mid + 1, r, L, C)
		return l

	def minDaysToEmpty(self, c, l):
		if c <= l:
			return c
		return self.binarysearch(l + 1, l + 1 + c, l, c)


class Solution:

	def minDaysToEmpty(self, c: int, l: int) -> int:
		max_c = c
		i = 1
		while c > 0:
			c -= i
			if c <= 0:
				return i
			else:
				c += l
				c = c if c <= max_c else max_c
				i += 1


class Solution:

	def minDaysToEmpty(self, c, l):
		t = c
		count = 0
		i = 1
		while t > 0:
			if l + t > c:
				t = c
			else:
				t += l
			t -= i
			count += 1
			i += 1
		return count


class Solution:

	def minDaysToEmpty(self, c, l):
		fill = 0
		total = c
		while total >= 0:
			fill = fill + 1
			total = total - fill
			if total <= 0:
				break
			total = total + l
			if total > c:
				total = c
		return fill


class Solution:

	def minDaysToEmpty(self, c, l):
		i = 0
		sum1 = c
		while sum1 > 0:
			sum1 += l
			if sum1 > c:
				sum1 = c
			sum1 -= i
			i = i + 1
		return i - 1


class Solution:

	def minDaysToEmpty(self, c, l):
		totalDays = 0
		totalCap = c
		i = 1
		while c > 0:
			c -= i
			totalDays += 1
			if c <= 0:
				break
			i += 1
			if c + l >= totalCap:
				c = totalCap
			else:
				c += l
		return totalDays


class Solution:

	def minDaysToEmpty(self, c, l):
		total = l
		rem = c - l
		new_sum = 0
		while new_sum < rem:
			total += 1
			new_sum += total - l
		return c if total > c else total


class Solution:

	def minDaysToEmpty(self, c, l):
		day = 1
		a = c
		while c > 0:
			c -= day
			if c <= 0:
				return day
			c = min(c + l, a)
			day += 1
		return day


class Solution:

	def minDaysToEmpty(self, c, l):
		day = 1
		temp = c
		while c > 0:
			c = c - day
			if c <= 0:
				break
			day += 1
			c += l
			if c > temp:
				c = temp
		return day


class Solution:

	def minDaysToEmpty(self, c, l):
		water = c
		day = 1
		water = water - day
		while water > 0:
			day += 1
			water = water + l
			if water > c:
				water = c
			water = water - day
		return day


def getCalculateSum(mid):
	return int(mid * (mid + 1) / 2)

class Solution:

	def minDaysToEmpty(self, c, l):
		if c <= l:
			return c
		low = 0
		high = 10000.0
		while low < high:
			mid = int(low + (high - low) // 2)
			if getCalculateSum(mid) >= c - l:
				high = mid
			else:
				low = mid + 1
		return l + low


class Solution:

	def minDaysToEmpty(self, c, l):
		count = 1
		initial = c
		c = c - 1
		day = 1
		while c > 0:
			day += 1
			c = c + l
			if c > initial:
				c = initial
			c = c - day
			count += 1
		return count


class Solution:

	def minDaysToEmpty(self, c, l):
		(i, t) = (1, c)
		while True:
			c += l if i > 1 else 0
			c = min(t, c)
			c -= i
			if c <= 0:
				return i
			i += 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		c = int(input())
		l = int(input())
		ob = Solution()
		print(ob.minDaysToEmpty(c, l))


import math

class Solution:

	def minDaysToEmpty(self, c, l):
		if l >= c:
			return c
		ans = (math.sqrt(1 + 8 * (c - l)) - 1) / 2
		return l + math.ceil(ans)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		c = int(input())
		l = int(input())
		ob = Solution()
		print(ob.minDaysToEmpty(c, l))


class Solution:

	def minDaysToEmpty(self, c, l):
		p = c
		i = 1
		while c - i != 0:
			c = c - i
			if c <= 0:
				break
			c = c + l
			if c >= p:
				c = p
			i += 1
		return i
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		c = int(input())
		l = int(input())
		ob = Solution()
		print(ob.minDaysToEmpty(c, l))


class Solution:

	def minDaysToEmpty(self, c, l):
		day = 1
		a = c
		while True:
			a += l
			if a >= c:
				a = c
				a -= day
			else:
				a -= day
			if a <= 0:
				return day
			else:
				day += 1


class Solution:

	def minDaysToEmpty(self, c, l):
		n = 1
		cap = c
		while c > n:
			c = c - n
			n += 1
			c = c + l
			if c > cap:
				c = cap
		return n


def getCumulateSum(n):
	return int(n * (n + 1) / 2)

class Solution:

	def minDaysToEmpty(self, c, l):
		if c <= l:
			return c
		(lo, hi) = (0, 10000.0)
		while lo < hi:
			mid = int((lo + hi) / 2)
			if getCumulateSum(mid) >= c - l:
				hi = mid
			else:
				lo = mid + 1
		return l + lo


class Solution:

	def minDaysToEmpty(self, c, l):
		cap = c
		count = 1
		while True:
			cap -= count
			if cap <= 0:
				break
			if cap + l >= c:
				cap = c
			else:
				cap = cap + l
			count += 1
		return count


class Solution:

	def minDaysToEmpty(self, c, l):

		def func(z):
			val = c
			for i in range(1, z + 1):
				val += l
				if val > c:
					val = c
				val -= i
			if val <= 0:
				return True
			return False
		low = 1
		high = c
		while low < high:
			mid = (low + high) // 2
			if func(mid):
				high = mid
			else:
				low = mid + 1
		return high


class Solution:

	def minDaysToEmpty(self, c, l):
		summ = c
		count = 1
		while summ > 0:
			summ -= count
			if summ <= 0:
				return count
			else:
				summ += l
				if summ > c:
					summ = c
				count += 1


class Solution:

	def minDaysToEmpty(self, c, l):
		water = c
		ans = 1
		while water > 0:
			water = water - ans
			if water <= 0:
				return ans
			else:
				water = water + l
				if water > c:
					water = c
				ans = ans + 1


import math

class Solution:

	def minDaysToEmpty(self, c, l):
		if l >= c:
			return c
		else:
			d = math.ceil((-1 + pow(1 + 8 * (c - l), 0.5)) / 2)
			return d + l


class Solution:

	def minDaysToEmpty(self, c, l):
		count = 1
		amount = c
		while amount > 0:
			amount = amount + l
			if amount > c:
				amount = c
			amount -= count
			count += 1
		return count - 1


class Solution:

	def minDaysToEmpty(self, c, l):
		tank = c - 1
		day = 2
		while tank > 0:
			tank += l
			if tank > c:
				tank = c
			tank -= day
			day += 1
		return day - 1


class Solution:

	def minDaysToEmpty(self, c, l):
		capacity = c
		count = 0
		i = 1
		while True:
			count += 1
			c -= i
			if c <= 0:
				break
			c += l
			if c > capacity:
				c = capacity
			i += 1
		return count