Gold Rush
InterviewTime limit1sMemory limit256 MB
Split a bar of weight 2 to the n into halves with the fewest cuts so two shares of weights a and b can be formed.
- Level
Easy3 of 10
- Topics
- Bit manipulation, Math
- Solved
- No attempts yet
Problem
Kangsan and Jihyun were on an adventure when they found a mysterious cave deep in the forest. They walked in full of excitement, and at the very end of the cave they found one huge gold bar. The bar was far too big and heavy for the two of them to carry out.
While they were wondering what to do, Jihyun noticed the number written on the bar. At that moment a fairy appeared and spoke.
- Fairy: This bar is heavy. It weighs a whole femtograms. And goes as high as 62.
- Kangsan: Oh, then we are in luck! Jihyun's bag holds exactly femtograms and my bag holds exactly femtograms, and .
- Jihyun: But how do we cut the bar?
- Fairy: My magic can split any object into two exactly equal halves. The problem is that I can use it only once a day.
Once a day the fairy picks one of the pieces produced so far and cuts it into two equal halves. Some days later Kangsan and Jihyun divided every piece between their bags and left the cave. The pieces in Jihyun's bag weighed exactly femtograms in total, and the pieces in Kangsan's bag weighed exactly femtograms in total.
Find the smallest number of days that has to pass after they enter the cave before they can leave it.
Input
The first line contains the number of test cases ().
Each of the next lines contains three integers , , (, , ).
Output
For each test case, print on one line how many days passed when Kangsan and Jihyun left the cave as early as possible.