https://www.codetree.ai/missions/8/problems/play-number-game-with-computer-2/description
import sys
input = sys.stdin.readline
m = int(input())
a, b = map(int, input().split())
# num = [x for x in range(m)]
# print(num)
def binary_search(target, m):
left = 0
right = m-1
cnt = 0
while left <= right:
mid = (left+right)//2
cnt += 1
# print(f"{left} {right}: {cnt}")
if mid == target:
return cnt
elif mid > target:
right = mid -1
else:
left = mid+1
return -1
min_cnt = m
max_cnt = 0
for i in range(a-1, b):
min_cnt = min(binary_search(i, m), min_cnt)
max_cnt = max(binary_search(i, m), max_cnt)
print(min_cnt, max_cnt)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 가장 많은 데이터 Python (0) | 2024.08.08 |
---|---|
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
[Codetree] 숫자의 개수 Python (0) | 2024.08.07 |