ISQRT

This function returns the integer square root of a nonnegative integer.

The integer square root is the floor of the exact square root:

\operatorname{isqrt}(n) = \left\lfloor \sqrt{n} \right\rfloor

It is the greatest integer r such that r^2 \le n.

Excel Usage

=ISQRT(n)
  • n (int, required): Nonnegative integer input.

Returns (int): Largest integer whose square is less than or equal to the input.

Example 1: Integer square root of perfect square

Inputs:

n
144

Excel formula:

=ISQRT(144)

Expected output:

12

Example 2: Integer square root rounds down for non-square

Inputs:

n
200

Excel formula:

=ISQRT(200)

Expected output:

14

Example 3: Integer square root of zero

Inputs:

n
0

Excel formula:

=ISQRT(0)

Expected output:

0

Example 4: Integer square root of a large integer

Inputs:

n
123456789

Excel formula:

=ISQRT(123456789)

Expected output:

11111

Python Code

from math import isqrt as math_isqrt

def isqrt(n):
    """
    Compute the integer square root of a nonnegative integer.

    See: https://docs.python.org/3/library/math.html#math.isqrt

    This example function is provided as-is without any representation of accuracy.

    Args:
        n (int): Nonnegative integer input.

    Returns:
        int: Largest integer whose square is less than or equal to the input.
    """
    try:
        if isinstance(n, bool):
            return "Error: n must be an integer"

        n_value = int(n)
        if float(n) != float(n_value):
            return "Error: n must be an integer"
        if n_value < 0:
            return "Error: n must be nonnegative"

        return int(math_isqrt(n_value))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Nonnegative integer input.