FLINT3.7.0-dev

flint_mpn_divisible

Synopsis#include <flint/mpn_extras.h>
int flint_mpn_divisible(mp_srcptr a, mp_size_t an, mp_srcptr b, mp_size_t bn)source

Returns 1 if b divides a and 0 otherwise. Requires \mathit{bn} \ge 1 and b_{bn-1} \ne 0; a may have zero top limbs and \mathit{an} may be zero or less than \mathit{bn}. Used by fmpz_divisible.

After the trivial cases and the 2-adic part (b = 2^v B^k b' with b' odd), one-limb b' use the Hensel remainder mpn_modexact_1_odd. When both the divisor and the quotient have at least 16 limbs, the operands are first screened modulo 2^{48} - 1 (which has nine small prime factors; flint_mpn_mod_2exp48m1): a prime dividing b but not a is revealed for about 60% of random pairs. Then, with m = \mathit{an} - \mathit{bn} + 1: b' of at most FLINT_MPN_DIVEXACT_SMALL_BN limbs use _flint_mpn_divisible_small; huge operands (\min(m, \mathit{bn}) \ge FLINT_MPN_DIVEXACT_NEWTON_CUTOFF, or \mathit{bn} \ge FLINT_MPN_DIVEXACT_UNBALANCED_CUTOFF and m \ge 8 \mathit{bn}) take the candidate quotient from the Newton Hensel division and form only the high part of its product with b (_flint_mpn_mulhigh_known_low), the low part being known; otherwise, as in GMP's mpn_divisible_p, a Hensel division with remainder (ports of mpn_sbpi1_bdiv_qr and mpn_dcpi1_bdiv_qr, the latter from FLINT_MPN_DC_BDIV_QR_CUTOFF limbs) is done after padding a so that its top limb is below that of b', and b' divides a if and only if the remainder equals b'.

Cite this page

The FLINT team, “flint_mpn_divisible (mpn_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/mpn_extras/flint_mpn_divisible.html (generated 2026-10-20).