Problem 5: Whither leads 3n+1?
Background:
The (semi) famous 3n+1 problem concerns the function f(n) whose value
is 3n+1 if n is odd and n/2 if n is even.
Thus f(3) is 10 and f(10) is 5.
When one repeatedly applies f, computing f(x), f(f(x)), f(f(f(x))),
etc., the result invariably gets to 1, whereafter it is a continual loop:
1 -> 4 -> 2 -> 1 -> ...
However, mathematicians have not been able to prove that this always occurs.
Professor Al Gorthm wants to study this matter and its (he/she/it's from pluto)
first question is how many steps are necessary to get to 1 for various
numbers. For instance, for 1, zero steps, for 2, one step, and for 3, 7 steps
because 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1.
Input:
The input will consist numbers, one per line,
ending with a 0 indicating end of input.
The numbers will have no more than 40 digits.
Output:
For each number (other than the terminating 0), write the number
followed by the number of steps for that number on a line.
If any step leads to a number of more than 40 digits, output the
number followed by "terms get too big".
Sample Input:
4
13
1
3333333333333333333333333333333333333333
0
Sample Output:
4 2
13 9
1 0
3333333333333333333333333333333333333333 terms get too big