Fraction Tree
It's almost Christmas, and MAPS has its own way of celebrating it. This year, Parsa is in charge of bringing the tree to the office — and he came up with a beautiful one.
Parsa's tree is a binary tree, where each vertex is labeled with a fraction of the form a_i / b_i. Here's how he built the tree:
1. The root of the tree is 1 / 1, i.e., a_1 = b_1 = 1.
2. The left child of vertex i with fraction a_i / b_i is defined as: a_2i = a_i + b_i, b_2i = b_i.
3. The right child of vertex i with fraction a_i / b_i is defined as: a_(2i + 1) = a_i, b_(2i + 1) = a_i + b_i.
Now, Parsa gives you a fraction of the form p / q and wants you to calculate its distance from the root.
Input Format:
The first line are integers p and q.Output:
Output the distance of the fraction p / q from the root of the tree.Sample Input:
3 5
Sample Output:
3