#!/usr/bin/python import sys; import math; lim = 1000000 maxLength = 0 maxChain = 0 def collatz(num): counter = 1 while(num is not 1): if(num % 2 == 0): num /= 2 else: num = num*3 + 1 counter += 1 return counter for i in range(1,lim): length = collatz(i) if(length > maxLength): maxLength = length maxChain = i print maxChain