Last active
January 15, 2019 10:46
-
-
Save abidkhan484/35bb1357e75c641c30a4af7a6abb10e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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