galois.isqrt

galois.isqrt(n)

Computes \(x = \lfloor\sqrt{n}\rfloor\) such that \(x^2 \le n < (x + 1)^2\).

Note

This function is included for Python versions before 3.8. For Python 3.8 and later, this function calls math.isqrt() from the standard library.

Parameters

n (int) – A non-negative integer.

Returns

The integer square root of \(n\).

Return type

int

Examples

In [1]: galois.isqrt(27**2 - 1)
Out[1]: 26

In [2]: galois.isqrt(27**2)
Out[2]: 27

In [3]: galois.isqrt(27**2 + 1)
Out[3]: 27