You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
355 B
Python

def my_sqrt(x):
if x<2: return x
left=1
right=int(x/2)+1
while left<=right:
mid=int((left+right)/2)
if mid*mid==x:
return mid
if mid*mid>x:
right=mid-1
else:
left=mid+1
return right
print(my_sqrt(16))