Advertisement
DimaT1

146

Aug 11th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. #-*-coding:utf8;-*-
  2. #qpy:2
  3. #qpy:console
  4.  
  5. def mysqrt(a):
  6.   if a == 0: return 0
  7.  
  8.   top = a
  9.   bottom = 1
  10.   x = (top + bottom) // 2
  11.  
  12.   while (top > bottom):
  13.     if(x*x < a):
  14.       bottom = x+1
  15.     else:
  16.       top = x-1
  17.     x = (top + bottom) // 2
  18.  
  19.   while (x+1)*(x+1) <= a:
  20.     x+=1
  21.   while x*x > a:
  22.     x-= 1
  23.   return x
  24.  
  25. #*****************
  26. a = int(input())
  27. print(mysqrt(a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement