spoj#MOVMRBL. Move Marbles
Move Marbles
You have N marbles and K slots. You have to follow the below mentioned rules :
- You can put in a marble or take out a marble from slot numbered 1 at any time.
- You can put in a marble or take out a marble from slot numbered i only if there exists a marble at the slot i - 1.
- The game stops when a marble reaches the slot numbered K for the first time.
Your task is to finish the game in minimum number of valid moves.
Input
The first line contains t, the number of testcases. Then on each line is given two numbers N <= 15, K <= 2^N - 1.
Output
Print two numbers namely the number of "put in" moves and the number of "remove from" moves respectively for all the tests such that you move to the Kth slot in minimum number of valid moves. See explanation section below for more details.
Example
Input:
1
3 6
Output:
6 3
Explanation :
The following are the valid moves for the given input:
PUT IN 1
PUT IN 2
PUT IN 3
REMOVE FROM 2
REMOVE FROM 1
PUT IN 4
PUT IN 5
REMOVE FROM 4
PUT IN 6