Skip to content

Instantly share code, notes, and snippets.

@abidkhan484
Last active January 15, 2019 10:46
Show Gist options
  • Select an option

  • Save abidkhan484/35bb1357e75c641c30a4af7a6abb10e3 to your computer and use it in GitHub Desktop.

Select an option

Save abidkhan484/35bb1357e75c641c30a4af7a6abb10e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# accepted
import sys
ll = 1000001
arr = [0] * ll
arr[0], arr[1] = 0, 1
def cycle_length(a, count=1):
if a == 1:
return count
if a < ll and arr[a]:
return count+arr[a]-1
if not (a & 1):
return cycle_length(a//2, count+1)
return cycle_length((3*a)+1, count+1)
for i in range(2, ll):
if not arr[i]:
c = cycle_length(i)
arr[i] = c
p = i + i
while (p < ll):
c += 1
# if not arr[p]: arr[p] = c
arr[p] = c
p += p
for line in sys.stdin:
i, j = map(int, line.split())
maxim = -1
for p in range(min(i,j), max(i,j)+1):
maxim = max(maxim, arr[p])
print(i, j, maxim)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment