Problem B
Collatz Conjecture
The Collatz Conjecture is an interesting phenomenon. Though its principle is very simple, it still remains among unresolved problems in mathematics, even after many years of study. However, the years of intensive research brought at least some results, which is a huge advantage of the human race against the aliens, because they did not study the conjecture for so many years. We want to keep this advantage.
Imagine a sequence defined recursively as follows: Start
with any positive integer
-
if
is even, then (“half …”) -
if
is odd, then (“…or triple plus one”)
The Collatz Conjecture says that every such sequence will
eventually reach
In this problem, you are given two starting values and your
task is to say after how many steps their sequences “meet” for
the first time (which means the first number that
occurs in both sequences) and at which number is it going to
happen. For simplicity, we will assume that the sequence does
not continue once it has reached the number one. In reality, it
would then turn into
Input
The input contains at most
The last test case is followed by a line containing two zeros.
Output
For each test case, output the sentence “
Sample Input 1 | Sample Output 1 |
---|---|
7 8 27 30 0 0 |
7 needs 13 steps, 8 needs 0 steps, they meet at 8 27 needs 95 steps, 30 needs 2 steps, they meet at 46 |