https://www.acmicpc.net/status?user_id=aiden1212&problem_id=13706&from_mine=1
math 모듈에서 제공하는 sqrt()는 가볍게 시간초과 에러가 뜬다.
따라서 이진탐색을 이용하여 문제를 풀어주면 된다.
def binary_search(target):
left, right = 0, 10**800-1
while left <= right:
mid = (left+right)//2
if target == mid**2:
print(mid)
return
elif target > mid**2:
left = mid+1
elif target < mid**2:
right = mid-1
return
binary_search(int(input()))
'자료구조,알고리즘(Python) > 백준' 카테고리의 다른 글
11582 : 치킨 TOP N (Python) (0) | 2024.09.10 |
---|---|
11663 : 선분 위의 점(Python) (1) | 2024.09.07 |
Python_(Binary search에 관한 문제들) (1) | 2024.09.03 |
(백준) 1463 : Python (0) | 2024.08.29 |
백준 : 17219(Python) (0) | 2024.08.23 |