Problem:


コラッツの予想

正の整数 n に対し、

n が偶数の時は 2 で割る。

n が奇数の時は 3 倍し、1 を足す。

という操作を繰り返すと結果が 1 になります。任意の正の整数 n に対してこの操作を繰り返すと必ず 1 になるであろうというのが「コラッツの予想」と呼ばれる問題です。この問題は日本では、「角谷の問題」としても知られている未解決の問題です。コンピュータを利用して非常に大きな数 3 &times; 253 = 27,021,597,764,222,976 以下については反例がないことが知られていますが、数学的には証明されていません。

整数 n を入力とし、結果が 1 になるまでに繰り返される操作の回数を出力するプログラムを作成してください。整数 n は 1 以上でかつ上記の計算を繰り返す途中の値が 1000000 以下となる程度の整数とします。たとえば、入力として 3 を受け取った場合は、操作列は

3 → 10 → 5 → 16 → 8 → 4 → 2 → 1

になるので、操作の回数（上の矢印の個数）である 7 を出力します。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットとして１つの整数 n (n ≤ 1000000) が１行に与えられます。

データセットの数は 50 を越えない。

Output

データセットごとに操作の回数を１行に出力します。

Sample Input

3
10
0

Output for the Sample Input

7
6



Sample input:
3
10
0


Sample output:
7
6

Submission status: Wrong Answer

Solution code:
def f(n, c):
    c += 1
    if n % 2 == 0:
        n = n / 2
    else:
        n = 3*n + 1
    
    if n == 1:
        print c
        return
    else:
        return f(n, c)

while True:
    n = int(raw_input())
    if n == 0: break
    c = 0
    f(n, c)

Submission status: Wrong Answer

Solution code:
def f(n, c):
    c += 1
    if n % 2 == 0:
        n = n / 2
    else:
        n = 3*n + 1
    
    if n == 1:
        c += 1
        print c
        return
    else:
        return f(n, c)

while True:
    n = int(raw_input())
    if n == 0: break
    c = -1
    f(n, c)

Submission status: Wrong Answer

Solution code:
def f(n, t):
    if n % 2 == 0:
        n = int(n / 2)
    else:
        n = n * 3 + 1
    t += 1
    if n == 1:
        return t
    else:
        return f(n, t)


while True:
    _n = int(input())
    if _n == 0:
        break
    print(f(_n, 0))

Submission status: Wrong Answer

Solution code:
def f(n, t):
    if n % 2 == 0:
        n = int(n / 2)
    else:
        n = n * 3 + 1
    t += 1
    if n == 1:
        return t
    else:
        return f(n, t)


while True:
    _n = int(input())
    if _n == 0:
        break
    print(_n if _n == 1 else f(_n, 0))

Submission status: Accepted

Solution code:
def f(n):
  if n in d: return d[n]
  if n==1: return 0
  if n % 2 ==0: c = f(n/2)+1
  else: c = f(n*3+1)+1
  d[n] = c
  return c

d = {}
while 1:
  n = int(raw_input())
  if n==0: break
  print f(n)

Submission status: Accepted

Solution code:
while 1:
  n = int(raw_input())
  if n==0: break
  c = 0
  while n != 1:
    if n % 2 ==0: n/=2
    else: n = n*3+1
    c += 1
  print c

Submission status: Accepted

Solution code:
while 1:
  n = int(raw_input())
  if n==0: break
  c = 0
  while n != 1:
    if n % 2 ==0:
      n/=2
    else:
      n = n * 3 + 1
    c += 1
  print c

Submission status: Accepted

Solution code:
while 1:
  n = int(raw_input())
  if n==0: break
  c=0
  while n!=1:
    n=[n/2,n*3+1][n%2]
    c+=1
  print c

Submission status: Accepted

Solution code:
while 1:
  n = input()
  if n==0: break
  c=0
  while n>1:
    n = n*3+1 if n%2 else n/2
    c += 1
  print c

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-

while True:
	n = int(raw_input())
	if n == 0: break
	
	ans = 0
	while n > 1:
		if n % 2 == 0: n = n / 2;
		else: n = n * 3 + 1
		ans += 1
	print ans

Submission status: Accepted

Solution code:
def f(n, c):
    if n == 1:
        print c
        return
    else:
        if n % 2 == 0:
            n = n / 2
        else:
            n = 3*n + 1
        c += 1
        return f(n, c)

while True:
    n = int(raw_input())
    if n == 0: break
    c = 0
    f(n, c)

Submission status: Accepted

Solution code:
def col(a):
    i=0
    while a!=1:
        if a%2==0:a//=2
        else:a=3*a+1
        i+=1
    return i
while True:
    a=input()
    if a!=0:print(col(a))
    else:break

Submission status: Accepted

Solution code:
def f(n, t):
    if n % 2 == 0:
        n = int(n / 2)
    else:
        n = n * 3 + 1
    t += 1
    if n == 1:
        return t
    else:
        return f(n, t)


while True:
    _n = int(input())
    if _n == 0:
        break
    print(0 if _n == 1 else f(_n, 0))

Submission status: Accepted

Solution code:
while True: 
  a = int(input()) 
  if a == 0: 
    break 
  count = 0 
  while a != 1: 
    if a % 2 == 0: 
      a //= 2 
      count += 1 
    else: 
      a = (a * 3) + 1 
      count += 1 
  print(count)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    ans = 0
    if n == 0:
        break
    while n > 1:
        ans += 1
        if n % 2 == 0:
            n = n/2
        else:
            n = 3 * n + 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break
    count = 0
    while n!=1:
        n = n//2 if n%2==0 else 3*n+1
        count += 1
    print(count)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    c=0
    while n!=1:
        if n%2:n=n*3+1 
        else:n/=2
        c+=1
    print(c)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    c=0
    while n!=1:
        n=n*3+1 if n%2 else n/2
        c+=1
    print(c)

Submission status: Accepted

Solution code:
def collatz(n,m):
    if n==1:
        return(m)
    if n % 2 == 0:
        return(collatz(n/2, m+1))
    else:
        return(collatz(3*n+1, m+1))

while True:
    n = int(input().strip())
    if n == 0:
        break
    print(collatz(n,0))

Submission status: Accepted

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break

        else:
            cnt = 0
            while True:
                if n == 1:
                    break
                elif n % 2 == 0:
                    n /= 2
                    cnt += 1
                elif n % 2 != 0:
                    n = n * 3 + 1
                    cnt += 1
            print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# Aizu Problem 00158: Collatz's Problem
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def collatz(n):
    steps = 0
    while n != 1:
        steps += 1
        if n % 2 == 0:
            n //= 2
        else:
            n = 3 * n + 1
    return steps


while True:
    n = int(input())
    if n == 0:
        break
    print(collatz(n))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    cnt = 0
    while n != 1:
        n = 3*n+1 if n % 2 else n//2
        cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0158

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        count = 0
        while n != 1:
            if n % 2 == 0:
                n //= 2
            else:
                n *= 3
                n += 1
            count += 1
        print(count)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    a=0
    if n==0:
        break
    while True:
        if n==1:
            print(a)
            break
        elif n%2==1:
            n*=3
            n+=1
            a+=1
        elif n%2==0:
            n/=2
            a+=1

Submission status: Accepted

Solution code:
while True:
    num = int(input())

    if num == 0:
        break

    count = 0

    while num != 1:

        if num % 2 == 0:
            num >>= 1
            count += 1
        else:
            num += num // 2 + 1
            count += 2

    print(count)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break

    ans = 0
    while N != 1:
        if N % 2 == 0:
            N = N / 2
        else:
            N = 3*N + 1
        ans = ans + 1
    print(ans)

Submission status: Accepted

Solution code:
# AOJ 0158: Collatz's Problem
# Python3 2018.6.18 bal4u

while True:
	n = int(input())
	if n == 0: break
	k = 0
	while n > 1:
		if n & 1:
			n = n + ((n+1)>>1)
			k += 2
		else:
			n >>= 1
			k += 1
	print(k)

Submission status: Accepted

Solution code:
def coll(n):
  cnt = 0
  while n > 1:
    if n % 2:
      n = n * 3 + 1
      cnt += 1
    while n % 2 == 0:
      n = n // 2
      cnt += 1
  return cnt

while True:
  n = int(input())
  if n == 0:
    break
  print(coll(n))

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    c=0
    while n<>1:
        n=n/2 if n%2==0 else n*3+1
        c+=1
    print c

Submission status: Accepted

Solution code:
table = {}
def memoize(f):
    global table
    def func(*args):
        if not args in table:
            table[args]=f(*args)
        return table[args]
    return func

@memoize
def func(n):
    if n == 1:
        return 0
    if n%2 == 1:
        return 1+func(n*3+1)
    else:
        return 1+func(n/2)

while True:
    n = input()
    if n == 0:
        break
    print func(n)

Submission status: Accepted

Solution code:
def collatz(n):
    if n==1: return 0
    return 1+collatz(n/2 if n%2==0 else 3*n+1)
while 1:
    n = input()
    if n==0: break
    print collatz(n)

Submission status: Accepted

Solution code:
def collatz(n):
	c = 0
	while n > 1:
		if n%2:	n = 3*n+1
		else: n /= 2
		c += 1
	return c
	
while True:
	n = int(raw_input())
	if n == 0: break
	print collatz(n)

Submission status: Accepted

Solution code:
def f(n):
	c=0
	while n>1:
		if n%2:n=3*n+1
		else:n /= 2
		c += 1
	print c
	
while 1:
	n=input()
	if n==0:break
	f(n)

Submission status: Accepted

Solution code:
def f(n):
	c=0
	while n>1:
		if n%2:n=3*n+1
		else:n/=2
		c+=1
	print c
	
while 1:
	n=input()
	if n==0:break
	f(n)

Submission status: Accepted

Solution code:
while True:
  N, c = input(), 0
  if not N:
    break
  while N > 1:
    if N % 2:
      N = N * 3 + 1
    else:
      N /= 2
    c += 1
  print(c)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0: exit()
  c = 0
  while n != 1:
    c += 1
    if n % 2 == 0:
      n /= 2
    else:
      n = n * 3 + 1
  print(c)

Submission status: Accepted

Solution code:
def a(n) :
    if n % 2 == 0 :
        return n // 2
    else :
        return n * 3 + 1

while True :
    n = int(input())
    if n == 0 :
        break
    
    ans = 0
    while n != 1 :
        n = a(n)
        ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
	n = int(input())
	if n == 0: break
	k = 0
	while n > 1:
		if n & 1:
			n = n + ((n+1)>>1)
			k += 2
		else:
			n >>= 1
			k += 1
	print(k)

Submission status: Accepted

Solution code:
while True:
    n = int(input());
    if n == 0:
        break;
    i = 0;
    while n != 1:
        i += 1;
        if n % 2 == 0:
            n = n / 2;
        else:
            n = n * 3 + 1;
    print(i);

Submission status: Accepted

Solution code:
def collatz(n):
    if n % 2 == 0:
        return n // 2
    else:
        return n * 3 +1
while True:
    n = int(input())
    if n == 0:
        break
    a = 0
    while n != 1:
        n = collatz(n)
        a += 1
    print(a)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    else:
        a=0
        while True:
            if n==1:
                print(a)
                break
            elif n%2==0:
                n/=2
                a+=1
            else:
                n*=3
                n+=1
                a+=1

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!


    
def coll(n):    
    k=0
    while n>1:
        if n%2:
            n=n*3+1
            k+=1
        while n%2==0:
            n=n//2
            k+=1
    return k
    
while True:
    n=int(input())
    if n==0:
        break
    print(coll(n))

Submission status: Accepted

Solution code:
def collatz(n):
    i=0
    while n != 1:
        
        if n%2==0:
            n = n/2
            i=i+1
        else:
            n=3*n+1
            i=i+1
    return(i)
    
while True:
    n=int(input())
    if n==0:
        break
    print(collatz(n))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
   n = int(input())
   if n == 0: break
   
   c = 0
   while n != 1:
      if n % 2 == 0:
         n /= 2
      else:
         n = n * 3 + 1
      c += 1
   print(c)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    count=0
    while n!=1:
        if n%2==1:
            n=n*3+1
        else:
            n=n//2
        count+=1
    print(count)

Submission status: Accepted

Solution code:
def x(n):
    if n == 1:
        return 0
    elif n % 2 == 0:
        return x(n/2) + 1
    else:
        return x(n*3 + 1) + 1

while True:
    n = int(input())
    if n == 0:
        break
    print(x(n))

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  a = 0
  while n > 1:
    if n%2 == 0:
      n //= 2
      a += 1
    else:
      n = n*3+1
      a += 1
  print(a)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    count = 0
    if n == 0:
        break
    
    while True:
        if n == 1:
            break
        elif n % 2 == 0:
            n = n / 2
            count += 1
        else:
            n = n * 3 + 1
            count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    i = 0
    if n == 0:
        break
    while True:
        if n == 1:
            break
        if n % 2 == 0:
            n = n // 2
            i = i + 1
        elif n % 2 != 0:
            n = n * 3 + 1
            i = i + 1
    print(i)

Submission status: Accepted

Solution code:
#もし0のときは終了
#if文で偶数のとき、奇数の時で分ける
#結果が１になるまで繰り返し回数をカウント

while True:
    n = int(input())
    count = 0
    if n == 0:
        break
    while n != 1:
        if n%2 == 0:
            n = n/2
            count += 1
        else:
            n = n * 3 + 1
            count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    c = 0
    if n == 0:
        break

    while n != 1:
        c += 1
        if n % 2 == 0:
            n //= 2
        else:
            n = n * 3 + 1
    
    print(c)

Submission status: Accepted

Solution code:
#81 コラッツの予想

while 1:
    n = int(input())
    if n == 0:
        break
    
    ans = 0
    while n != 1:
        if n%2 == 0:
            n = n//2
            ans += 1
        else:
            n = n*3+1
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:
        break
    s=0        
    while n!=1:
        if n%2==0:
            n=n/2
            s+=1
        else:
            n=n*3+1
            s+=1
    print(s)

Submission status: Accepted

Solution code:
def Collatz(n) :
    if n % 2 == 0 :
        return n // 2
    else :
        return n * 3 + 1

while True :
    n = int(input())
    if n == 0 :
        break
    
    count = 0
    while n != 1 :
        n = Collatz(n)
        count += 1
    print(count)

Submission status: Accepted

Solution code:
def f(x,y):
    if x==1:
        return(y)
    if x%2==0:
        return(f(x/2,y+1))
    else:
        return(f(3*x+1,y+1))

while True:
    x=int(input().strip())
    if x==0:
        break
    print(f(x,0))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    n = int(input())
    if n == 0:
        break
    
    m = 0
    while n != 1:
        if n % 2 == 0:
            n //= 2
        else:
            n = n * 3 + 1
        m += 1
    print(m)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break

    cnt = 0
    while n != 1:
        if n % 2 == 0:
            n //= 2
        else:
            n = n * 3 + 1
        cnt += 1

    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:
        break
    m = 0
    while True:
        if n==1:
            break
        if n % 2==0:
            n = n / 2
            m += 1
        else:
            n = n * 3 + 1
            m += 1
    print(m)

Submission status: Accepted

Solution code:
def collatz(n):
    i=0
    while n != 1:
        if n%2==0:
            n = n/2
            i=i+1
        else:
            n=3*n+1
            i=i+1
    return(i)
    
while True:
    n=int(input())
    if n==0:
        break
    print(collatz(n))

Submission status: Accepted

Solution code:
def korat(x):
    i = 0
    while x > 1:
        if x % 2:
            x = x * 3 + 1
            i += 1
        while x % 2 == 0:
            x = x // 2
            i += 1
    return i

while True:
    n = int(input())
    if n == 0:
        break
    print(korat(n))

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break

    ans = 0
    while N != 1:
        if N % 2 == 0:
            N = N / 2
        else:
            N = 3*N + 1
        ans = ans + 1
    print(ans)

Submission status: Accepted

Solution code:
def co(x):
    m = 0
    while True:
        if x==1:
            break
        if x%2==0:
            x = x//2
            m+=1
        else:
            x = int(x*3+1)
            m+=1
    print(m)
while True:
    n = int(input())
    if n==0:
        break
    co(n)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    c=0
    while n>1:
        if n%2==0:
            n=n/2
        else:
            n=n*3+1
        c+=1
    print(c)

Submission status: Accepted

Solution code:
while True:
   x = int(input())
   if x == 0:
      break
   c=0
   while True:
      if x==1:
         break
      elif x%2==0:
         x = x//2
      else:
         x = x*3 +1
      c += 1
   print(c)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    else:
        s=0
        while True:
            if n==1:
                break
            elif n%2==0:
                n=n//2
                s+=1
            else:
                n=(n*3)+1
                s+=1
        print(s)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    sum=0
    if n==0:
        break
    while n>1:
        if n%2==0:
            n/=2
            sum+=1
        else:
            n=3*n+1
            sum+=1
    print(sum)

Submission status: Accepted

Solution code:
n=int(input())
while n!=0:
    c=0
    while n!=1:
        if n%2==0:
            n=n/2
            c=c+1
        else:
            n=n*3+1
            c=c+1
    print(c)
    n=int(input())

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    
    if n==0:
        break
    
    i=0
    
    while n!=1:
        if n%2==0:
            n=n/2
        else:
            n=3*n+1
        i+=1
    
    print(i)

Submission status: Accepted

Solution code:
while True:
    a = int(input())
    if a == 0:
        break
    c = 0
    
    while a != 1:
        c += 1
        if a %2:
            a = 3 * a +1
        else:
            a = a//2
    print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
# 81

while True:
    n=int(input())
    c=0
    if n==0:
        break
    while True:
        if n==1:
            break
    
        if n%2==0:
            n = n/2
            c += 1
        
        else:
            n = n*3+1
            c += 1
    print(c)

Submission status: Accepted

Solution code:
for i in range(50):
    n = int(input())
    
    if n == 0:    break
    
    i = 0
    while 1:
        if n == 1:  break
        if n % 2 == 0:
            n = n / 2
        else:
            n = n*3 + 1
        i += 1
    
    print(i)

Submission status: Accepted

Solution code:
#0518
while True:
    n = int(input())
    if n == 0:
        break
    c = 0
    while True:
        if n == 1:
            break
        if n%2 == 0:
            n = n//2
        else:
            n= n*3 + 1
        c += 1
    print(c)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0: break
    a=0
    while n>1:
        if n%2==0:
            n=n/2
            a+=1
        else:
            n=3*n+1
            a+=1
    print(a)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    k=0
    while True:
        if n==1:
            break
        elif n%2==0:
            n=int(n/2)
            k+=1
        else:
            n=n*3+1
            k+=1
        
    print(k)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break
    count = 0
    while n!=1:
        n = n//2 if n%2==0 else 3*n+1
        count += 1
    print(count)

Submission status: Accepted

Solution code:
while True:
    a=0
    x=int(input())
    if x == 0:
        break
    while x!=1:
        if x%2 == 0:
            x=x/2
            a+=1
        else:
            x=3*x+1
            a+=1
            
    print(a)

Submission status: Accepted

Solution code:
def f(x,y):
    if x==1:
        return(y)
    if x%2==0:
        return(f(x/2,y+1))
    else:
        return(f(3*x+1,y+1))

while True:
    x=int(input().strip())
    if x==0:
        break
    print(f(x,0))

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    else:
        i=0
        while True:
            if n==1:
                break
            else:
                i+=1
                if n%2==0:
                    n=n//2
                else:
                    n=3*n+1
        print(i)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    c=0
    while n!=1:
        if n%2==1:
            n=n*3+1
            c+=1
        else:
            n=n//2
            c+=1
    print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
   n = int(input())
   if n == 0: break
   
   c = 0
   while n != 1:
      if n % 2 == 0:
         n /= 2
      else:
         n = n * 3 + 1
      c += 1
   print(c)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    
    ans = 0    
    while n != 1:
        
        if n % 2 == 0:
            n = n/2
        else:
            n = n*3+1
        
        ans += 1
    
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    count=0
    if n==0:
        break
    while True:
        if n==1:
            break
        elif n%2==0:
            n=n/2
            count+=1
        else:
            n=n*3+1
            count+=1
    print(count)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    
    if n==0:
        break
    
    count = 0
    while True:
        if n==1:
            break
    
        if n%2==0:
            n = int(n/2)
            count += 1
            continue
        if n%2==1:
            n = int(3*n+1)
            count += 1
            continue
        
        if n==1:
            break
    
    print(count)
    
    continue

Submission status: Accepted

Solution code:
#入力値0になるまで繰り返す
while True:
    num = int(input())
    if num == 0:break

#numが偶数の時は22で割り、奇数のときは3倍し1を足す
    else:
        kei = 0
        while num != 1:
            if num % 2 == 0:num /= 2
            else:
                num *= 3
                num += 1
            kei += 1
        print(kei)

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    
    if n == 0 :
        break
    else :
        cnt = 0
        
        while True:
            if n == 1 :
                print(cnt)
                break
            
            elif n % 2 == 0 :
                n /= 2
                cnt += 1
                
            else :
                n *= 3
                n += 1
                cnt += 1

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    s=0
    if n==0:
        break
    while n!=1:
        if n!=0:
            if n%2==0:
                n=n/2
                s+=1
            else:
                n=n*3+1
                s+=1
    print(s)

Submission status: Accepted

Solution code:
def collatz(n):
    c = 0
    while n > 1:
        if n % 2 == 0:
            n  = n / 2
            c += 1
        else:
            n = n * 3 + 1 
            c += 1
    return c
    
while 1:
    n = int(input())
    if n == 0:
        break
    else:
        print(collatz(n))

Submission status: Accepted

Solution code:
import sys
import math
def koratsu(n,i):
    if(n==1):
        return i
    elif(n%2==0):
        n=n//2
        i=i+1
        return koratsu(n,i)
    else:
        n=3*n+1
        i=i+1
        return koratsu(n,i)
i=0
while i<50:
    n=int(input())
    if(n==0):
        break
    kaisu=koratsu(n,i)
    print(str(kaisu))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    c = 0
    
    while n != 1:
        c += 1
        if n %2:
            n = 3 * n +1
        else:
            n = n//2
    print(c)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    k = 0
    while n > 1:
        if n & 1:
            n = n + ((n+1)>>1)
            k += 2
        else:
            n >>= 1
            k += 1
    print(k)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break
    count = 0
    while True:
        if n==1:
            print(count)
            break
        elif n % 2 ==0:
            n /= 2
            count +=1
        else:
            n*=3
            n+=1
            count += 1

Submission status: Accepted

Solution code:
while True:
  n =int(input())
  if n==0:
    break
  num=0
  while n!=1:
    if n%2==0:
      n=n/2
      num+=1
    else:
      n=n*3+1
      num+=1
      
  print(num)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    c=0
    while n!=1:
        n=n*3+1 if n%2 else n/2
        c+=1
    print(c)

Submission status: Accepted

Solution code:
def process(n, x):
    if n != 1:
        if n % 2 == 0:
            x += 1
            return process(n//2, x)
        else:
            x += 1
            return process(n*3+1, x)
    else:
        return x

while True:
    n = int(input())
    if n == 0: break
    print(process(n, 0))

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if not n:break
    a=0
    while n>1:
        if n%2:
            n=3*n+1
        else:
            n//=2
        a+=1
    print(a)

Submission status: Runtime Error

Solution code:
d = {}
while 1:
  n = int(raw_input())
  if n==0: break
  c = 0
  while n != 1
    if n % 2 ==0: n/=2
    else: n = n*3+1
    c += 1
  print c

Submission status: Runtime Error

Solution code:
M = 10**6; dp = [-1]*M; dp[0],dp[1] = 0,0;
def collatz(n):
    if dp[n]!=-1: return dp[n]
    dp[n] = 1+collatz(n/2 if n%2==0 else 3*n+1)
    return dp[n]
while 1:
    n = input()
    if n==0: break
    print collatz(n)