Baekjoon Online Judge

[python]13706. 제곱근

kickerLit 2021. 9. 28. 21:43

제곱근을 구하는 것인데 이분탐색으로 구하여야만 

통과할 수 있는 문제다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
= int(input())
lt = 1
rt = n
 
mid = n//2
 
while 1:
    if mid**2 == n:
        print(mid)
        break
 
    elif mid**2 > n:
        rt = mid-1
        mid = (lt+rt)//2
 
    else:
        lt = mid+1
        mid = (lt+rt)//2
        
        
 
cs

https://www.acmicpc.net/problem/13706

'Baekjoon Online Judge' 카테고리의 다른 글

[c++]2309.일곱난쟁이  (0) 2021.09.21
[python]1182. 부분수열의 합  (0) 2021.04.29
[python]7568. 덩치  (2) 2021.04.29
[python]1914.하노이 탑  (0) 2021.02.11
[python]10814.나이순 정렬  (4) 2021.02.03