Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isqrt(n):
- """Uses Newton's method to calculate floor(sqrt(x)) using
- speedy nice (and free of float weirdness!) integer math."""
- x = n
- y = (x + 1) // 2
- while y < x:
- x = y
- y = (x + n // x) // 2
- return y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement