flint_mpn_sqrtmod, flint_mpn_sqrtmod_preinv
#include <flint/mpn_extras.h>int flint_mpn_sqrtmod_preinv(nn_ptr res, nn_srcptr a, nn_srcptr d, mp_size_t n, nn_srcptr dinv, flint_bitcnt_t norm)sourceSets to a square root of modulo the odd prime and returns 1. Returns 0, setting res to zero, if the Jacobi symbol rules a root out (which is conclusive whether or not is prime), and , again setting res to zero, if the algorithm itself failed, which happens only for not prime (or, with negligible probability, for a prime whose least quadratic nonresidue exceeds ). The preinv version takes the inverse dinv of from flint_mpn_preinvn and , as an mpn_mod or fmpz_mod context holds them; dinv may be NULL.
For with odd, the root is a single exponentiation when (, or Atkin's formula); Tonelli–Shanks is used for , and Müller's variant of the Cipolla–Lehmer algorithm, whose cost does not depend on , for . See Square roots modulo a prime. The arithmetic is flint_mpn_mulmod_preinvn and flint_mpn_powmod_preinvn throughout.
The FLINT team, “flint_mpn_sqrtmod, flint_mpn_sqrtmod_preinv (mpn_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/mpn_extras/flint_mpn_sqrtmod.html (generated 2026-11-02).
@misc{flint-doc-mpn-extras-flint-mpn-sqrtmod,
author = {{The FLINT team}},
title = {{flint\_mpn\_sqrtmod, flint\_mpn\_sqrtmod\_preinv (mpn\_extras.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/mpn_extras/flint_mpn_sqrtmod.html},
note = {Generated 2026-11-02}
}