Harry and Jellies

0

0 votes
Easy-Medium
Problem

We all know that harry potter loves jellys from Fred and George's shop. One such day he went to the shop asking for jellies. Then Fred gave him N jellies. Before giving the jellies harry drunk a magical potion which has magic in it.The user manual of potion said,"The one who drinks it will eat twice jellies after eating C number of jellies and it will continue". Now Fred gives him N jellies. Harry want to know in what minimum time he will eat all jellies if he starts by eating 1 jelly.NOTE 1 POINT EVEN IF HE EAT 2*C jeelies the rate of eating will be 1 until he reaches c. Can you help him?

Input Format:
First lint of input consists of an integer T denoting the number of test cases. For each line there are two numbers N and C seperated by a space.
Output Format:
Output a single integer for each test case denotng the time required.

Constraints

1<=T<=1000

1<=N,C<=10^9

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

CASE 1: Here N is 10 and C is 1. So rate doubles after eating 1 jelly. 10 jellies can be finished by 1+2+4+3 equals 4 units of time. In last after 4 we write 3 as only 3 jellies will be remaining which harry can eat in 1 blow.

CASE 2:Here N=10 and C=5. Means after eating 5 jellies potion doubles harrys eating rate. So, 1+1+1+1+1+2+2+1 equals 8 unit of time. So harry will take 8 units of time to finish all jellies

Editor Image

?