FLINT3.7.0-dev

mpn_mod_inv

Synopsis#include <flint/mpn_mod.h>
int mpn_mod_inv(nn_ptr res, nn_srcptr x, gr_ctx_t ctx)source

Sets res to x−1 mod nx^{-1} \bmod n and returns GR_SUCCESS if gcd⁡(x,n)=1\gcd(x, n) = 1. Otherwise returns GR_DOMAIN, or GR_UNABLE if xx is nonzero and the ring pretends to be a field (recording gcd⁡(x,n)\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=±1x = \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-11-02).