BTW the problem is known as 3n+1 problem and you can find it in ACM archives too. http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36