


1. An axe that is used to cut a lesser or equal number of logs than its limit can be used again.
2. An axe that is used to cut more logs than its limit will be broken. Thus, it cannot be used again.
3. All the axes have the same limit of cutting logs until broken.
4. An axe may also cut N logs or may not even cut a single log.
Let the number of axes (K) be 2 & the capacity of the log cutting stand (N) be 6.

From the above example, we can see that the maximum number of moves is 3 for 2 axes and a capacity of 6 logs.
The first line of input contains an integer ‘T’ denoting the number of queries or test cases.
The first and only line of each input consists of 2 space-separated integers ‘K’ and ‘N’ denoting the number of axes and the capacity of log cutting stand simultaneously.
For each test case, print the minimum number of moves required to know the limit of the axe.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
Can you solve this in the worst-case time complexity of N ^ (1/3)
1 <= T <= 10
1 <= K <= 100
1 <= N <= 10000
The very first approach can be to try cutting logs and find the one with the minimum number of moves.
We are solving this problem by solving its subproblems and then combining the solutions of those subproblems. If we analyze carefully, we will see that we are solving the same subproblems multiple times. Thus, this problem exhibits overlapping subproblems. This means, in this approach, we will eliminate the need for solving the same subproblems again and again.
To optimize the overlapping sub-problem calculation, we will use memoization by storing answers for each recursive state.
Initially, we were breaking the large problem into small problems but now, let us look at it differently. Let us solve the small problem first and then reach the final answer. Thus we will be using a bottom-up approach now.
It is similar to the previous approach but in the previous approach, we are finding the point with the minimum required moves in a loop. But, in this approach, we will optimize that.
As, in the loop the first value i.e DP[i - 1][t - 1] (If axe couldn’t cut i logs) is increasing and the second value i.e DP[i][j - t] (If axe could cut i logs) is decreasing. So, we can find the optimum point using a binary search.
If we observe that each row in DP[ K ][ N ] is an increasing function in N. So, the optimal answer for current iteration will be greater than or equal to answer of the previous iteration. So, we will use this property to optimize the previous approach.
Now let's just solve the problem in another way. Previously we were solving the problem for K axes and N log cutting capacity. Now let's just calculate what is the maximum number of log capacity we can check with K axes in each move. So, our recurrence relation will be:
f(T, K) = f(T-1, K-1) + f(T-1, K) + 1
Using this recurrence relation we can answer each test case in worst-case time complexity of √N
First, let’s discuss some optimizations we are going to use.
In x moves with 2 eggs, we can check a capacity of (x × (x + 1)) / 2. Thus we get our equation to be. Solving this equation we get
x = ceil( ( -1 + √(1 + 8 × N) ) / 2 )
The algorithm to pre-compute DP tables is as follows.
Now as we have our DP table ready where row number defines the number of available axes and column number defines the number of required moves and entry in each cell defines the maximum number of cutting capacity it can check.
To answer each test case we will just find the entry in the Kth row which is greater than or equal to N.
The algorithm for the same is as follows.