Update Files
Contest: Educational Codeforces Round 116 (Rated for Div. 2)
Difficulty rating: 1100
Tags: greedy, implementation, math

Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.

Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.

Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.

Input format:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.

Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.

Output format:
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
Let's consider the test cases of the example:

- $$$n=8$$$, $$$k=3$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$;  during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$.
- $$$n=6$$$, $$$k=6$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$.
- $$$n=7$$$, $$$k=1$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$;  during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$;  during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$;  during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.

Example input:
4
8 3
6 6
7 1
1 1

Example output:
4
3
6
0

Editorial:
Let $$$cur$$$ be the current number of computers with the update already installed (initially it is $$$1$$$). Then, in $$$1$$$ hour, we can increase $$$cur$$$ by $$$\min(cur, k)$$$. From here we can see that the value of $$$cur$$$ will double for the first few hours, and then, when it becomes greater than $$$k$$$, it will begin to increase by exactly $$$k$$$.
The process when the number of computers doubles can be modeled using a loop, because the number of doublings does not exceed $$$\log{n}$$$. And after that, we have to increase the answer by $$$\left\lceil {\frac{n - cur}{k}} \right\rceil$$$ to take the number of additions of $$$k$$$ into account.
Note that computing $$$\left\lceil {\frac{n - cur}{k}} \right\rceil$$$ should be done without using fractional data types; to calculate $$$\left\lceil {\frac{x}{y}} \right\rceil$$$ in integers, you should divide $$$x + y - 1$$$ by $$$y$$$ using integer division (this will work provided that both $$$x$$$ and $$$y$$$ are non-negative, and $$$y \ne 0$$$). If you use real numbers, this may cause precision issues.