# # 1916
#
# yay = [0] * 205
#
# def pivo(n):
# global yay
# if n == 0:
# return 0
# elif n == 1 or n == 2:
# yay[n - 1] = 1
# return 1
# if yay[n] != 0:
# return yay[n]
# yay[n] = (pivo(n-2) + pivo(n-1))%10009
# return yay[n]
#
# n = int(input())
# print(pivo(n))
# 3733 UNFINISHED
import sys
sys.setrecursionlimit(1000000000)
a, b = map(int, input().split())
yay = [0] * 10000000
c = 0
def oobak(n):
if yay[n] != 0:
return yay[n]
elif n == 1:
return 1
elif n % 2 == 1:
return oobak(3 * n + 1) + 1
elif n % 2 == 0:
return oobak(n//2) + 1
for i in range(a, b+1):
x = oobak(i)
# NOT n = i HERE!!
if c < x:
n = i
'''
"만약 가장 긴 수가 두 개이상인 경우, 작은 숫자를 출력하시오."
we should put this n=i INSIDE the if sentence not the outer (for문) because
if we put it outside the IF then it will just save the newest n=i value
, which is the biggest num of the range inputted,
and print that at the end (print(n,c))
even when c is agreed to stay the lower value, n will change to biggest.
'''
c = x
print(n, c)
top of page

기능을 테스트하려면 라이브 사이트로 이동하세요.
20240825
20240825
댓글 0개
좋아요
댓글(0)
bottom of page