Description we can add 1 to an integer a or multiply it by 2 to convert it to another integer B. Given two integers x and y, it takes at least a few steps to convert X to Y .. The first line of input contains an integer T (1 ≤ T ≤ 500), indicating a total of T groups of test data. Each group of test data occupies one row, which contains two integers x, y (1 ≤ x ≤ y ≤ 1018 ). For each group of test data, the output must take at least several steps to convert X to Y. Sample Input
31 13 102 11
Sample output
034
Hint
For example 2, 3 is converted to-> 4-> 5-> 10 in three steps.
For example 3, you can convert 2 to> 4-> 5-> 10-> 11 in four steps.
Source
The Eighth Program Design Competition for Central South University Students
// Inverse consideration from Y to X. Use long # include <cstdio> long a, B; void solve () {long ans = 0; while (A <B) {If (A> B/2) {ans + = B-a, B =; // A> B/2 so that a becomes B, it can only be one by one plus 1} else {If (B % 2) ans + = 2, B/= 2; // if the remainder of B % 2 is not equal to 0, a must first add 1, multiply by 2 else ans ++, B/= 2 ;}} printf ("% LLD \ n", ANS) ;}int main () {int T, I; scanf ("% d", & T); While (t --) {scanf ("% LLD", & A, & B); solve ();} return 0 ;}
Csu_1410: Integer Conversion