Created
October 16, 2013 07:53
-
-
Save falsetru/7004147 to your computer and use it in GitHub Desktop.
우박 수열
This file contains 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
import functools | |
import sys | |
@functools.lru_cache(maxsize=None) # Python 3.2+ | |
def f(n): | |
if n == 1: | |
return 1 | |
elif n % 2 == 0: | |
return 1 + f(n // 2) | |
else: | |
return 1 + f(n * 3 + 1) | |
def solve(i, j): | |
return max(map(f, range(i, j+1))) | |
for line in sys.stdin: | |
i, j = map(int, line.split()) | |
print(i, j, solve(i, j)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment