Math module in Python contains a number of mathematical operations, which can be performed with ease using the module.
math.isqrt() method in Python is used to get the integer square root of the given non-negative integer value n. This method returns the floor value of the exact square root of n or equivalently the greatest integer a such that a2 <= n.
Note: This method is new in Python version 3.8.
n: A non-negative integer
Returns: an integer value which represents the floor of exact square root of the given non-negative integer n.
Code #1: Use of math.isqrt() method
Code #2: Use of math.isqrt() method to check whether the given integer is a perfect square.
100 is perfect square 10 is not a perfect square
Code #3: Use of math.isqrt() method to find the next perfect square of n.
Next perfect square after 11 is 16 Next perfect square after 37 is 49
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course