[백준] 13706번 제곱근, Python

이건회·2022년 1월 27일
0

백준

목록 보기
2/15
n=int(input())
start=1
end=n
def binary_search(start,end,n):
  while True:
    mid=(start+end)//2
    if mid**2==n:
      return mid
      break
    elif mid**2>n:
      end=mid-1
    else:
      start=mid+1
  return -1

print(binary_search(start,end,n))

sqrt 함수를 쓰면 런타임 에러가 떠서 이진 탐색을 써야한다

profile
하마드

0개의 댓글