|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/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
|