728x90
반응형

이분 탐색 문제이다. 이분 탐색 안쓰고 그냥 반복문 돌려서 풀면 시간 초과가 나온다.

n = int(input())
s, e = 0, int((2**63)**0.5)+1
res = 0
while s <= e:
    m = (s+e)//2
    if m**2 >= n:
        res = m
        e = m-1
    else:
        s = m+1
print(res)
728x90
반응형

+ Recent posts