Skip to content

Instantly share code, notes, and snippets.

@prat0318
Last active January 3, 2016 17:29
Show Gist options
  • Save prat0318/8495786 to your computer and use it in GitHub Desktop.
Save prat0318/8495786 to your computer and use it in GitHub Desktop.
import sys
cache = {}
while True:
c = sys.stdin.readline()
if c == '': break
a1, b1 = c.split()
a = int(a1); b = int(b1)
max_length = 0
a, b = min(a,b), max(a,b)
if a < b/2: a = b/2
for i in range(a, b+1):
i1 = i
cached = False
length = 0
while i != 1:
if i in cache:
length += cache[i]
cached = True
break
if i%2 == 0:
i = i >> 1
length += 1
else:
i = i + (i >> 1) + 1
length += 2
if not cached: length += 1
if i1 not in cache: cache[i1] = length
if length > max_length: max_length = length
print(a1+" "+b1+" "+str(max_length))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment