IIITA1 - Playing With Bits

no tags 

Maaz and Aradhya are quite brilliant students of Mathematics and Programming respectively. One day, their Mathematics Professor Mr. K.P. Singh asked them to solve a Mathematics problem.

Given two number A and B, find the minimum number of bits required to convert binary representation of A into binary representation of B.

Maaz promised Mr. K.P. Singh that he will be the first one to solve the problem but Aradhya decided to do it before him. He turns to you for help. Will you be able to help him?

Input

Input consists of t (number of test cases), then t lines follows, each containing two integers a and b (1 <= a,b <= 2^31)

Output

A single line containing the minimum number of bits required to convert binary representation of  A into binary representation of  B.

Example

Input:
2
14 31
56 68
Output:
2
5


Time Limit is kept very strict. Any naive algorithm will never be accepted.
 

hide comments
victor gomez: 2013-05-15 07:56:15

can some one doa tutorial, i need to solve this problem for a final exam; //plis should be in C++

Last edit: 2013-05-15 07:57:11
:D: 2012-08-26 21:15:52

Please don't set up such ridiculous times in the main problem set.

Also what do you mean by brute force? I think iterative approach with fast reading/writing will pass either way (I'll maybe check that tomorrow). The time here should simply be the IO time. Finally it's really basic so it lands in tutorial.

Last edit: 2012-08-27 05:51:46
StupidGuy: 2012-08-26 16:31:09

So, finally tutorial it is...

Shubham: 2012-08-26 16:31:09

@better late than never,problemID 7534417 and 7534410 are exactly the same but one got accepted and other one showed TLE. And by exact I mean exact.look into this please.

RE -> This is all due to SPOJ machine. If their is load on spoj machine execution time of the solution increases. And since time limit is kept strict, that might lead to TLE.

Last edit: 2012-08-26 20:13:49
mehmetin: 2012-08-26 16:31:09

As pointed out by S#!THAPPEN$, the judge can give TLE for no reason. It happens with other problems too. It must have something to do with the system.

Francky: 2012-08-26 16:31:09

Solution had been rejudged and I loose my 0.07s :-(
Why rejudge ? For the new strict time limit ? What a joke.
Move it to tutorial or challenge as many people ask to, please.

Secret: 2012-08-26 16:31:09

it should be moved to tutorial .

Alex Anderson: 2012-08-26 16:31:09

This should be tutorial or challenge.

Aradhya: 2012-08-26 16:31:09

:D check my submissions in id's 7532238 and 7532240.. not even a single character change :D one AC and one TLE.. lol on spoj machines

Aradhya: 2012-08-26 16:31:09

my c++ code which took 0.09 sec ,, got TLE in PYTH o.O.. reset the time limit snehasish


Added by:Better late than never !!!
Date:2012-08-25
Time limit:0.100s
Source limit:500B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Navneet Sir