galois.isqrt

class galois.isqrt(n)

Computes the integer square root of \(n\) such that \(\textrm{isqrt}(n)^2 \le n\).

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\) such that \(\textrm{isqrt}(n)^2 \le 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