P21790 [GeeksforGeeks] Empty the tank3831
普及-
题目描述

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}

输入格式

见题面

输出格式

见题面

样例输入
C = 5, L = 2
样例输出
4