mpn_mod_inv
Synopsis
#include <flint/mpn_mod.h>Sets res to x^{-1} \bmod n and returns GR_SUCCESS if \gcd(x, n) = 1. Otherwise returns GR_DOMAIN, or GR_UNABLE if x is nonzero and the ring pretends to be a field (recording \gcd(x, n), see Context objects); res is then left unchanged.
The inverse is computed with GMP's extended gcd mpn_gcdext, except for x = \pm 1, which are their own inverses.
Guides#
Cite this page
The FLINT team, “mpn_mod_inv (mpn_mod.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/mpn_mod/mpn_mod_inv.html (generated 2026-10-20).
@misc{flint-doc-mpn-mod-mpn-mod-inv,
author = {{The FLINT team}},
title = {{mpn\_mod\_inv (mpn\_mod.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/mpn_mod/mpn_mod_inv.html},
note = {Generated 2026-10-20}
}