FLINT3.7.0-dev
Module · 156 functions

ulong_extras.h

#include <flint/ulong_extras.h>

This module works with ulong, an unsigned integer of FLINT_BITS bits (64 on all common platforms). It provides division and modular arithmetic with precomputed inverses, primality testing, factoring, integer roots and elementary number-theoretic functions. Most higher-level modules (nmod, fmpz, the polynomial and matrix modules) rely on it.

For background, Choosing a method for modular arithmetic compares the ways of computing modulo a word-size integer, and Primality testing for word-size integers and Factoring word-size integers describe the algorithms behind n_is_prime and n_factor.

Conventions#

Throughout, B = 2^{\mathtt{FLINT\_BITS}}.

  • Functions ending in _preinv take a precomputed inverse of type ulong computed by n_preinvert_limb. Functions ending in _precomp take a double inverse computed by n_precompute_inverse.
  • A 2 in the name (n_mod2_preinv, n_mulmod2_preinv) marks the variant with no size restrictions on its inputs. Variants without it are faster but may require reduced operands, a normalised modulus or a modulus below 2^{53}.
  • n_ll_ and n_lll_ functions take operands of two or three limbs.
  • Precomputed inverses are assumed to match the modulus, and operands of modular functions are assumed to be reduced. None of this is checked.
OverviewChoosing a method for modular arithmeticFLINT has a dozen ways to compute modulo a word-size n, for single values, vectors, SIMD lanes and matrices. This page compares their requirements and costs and says which to use.

Basic arithmetic#

Returns the high word \lfloor ab / B \rfloor of the double-word product ab.

Sets *a to b + c, b - c or bc modulo B and returns 1 if the exact result does not fit in a ulong, otherwise 0.

Returns n^{\mathit{exp}}, with 0^0 = 1. Overflow is not detected.

Returns \lfloor \log_b n \rfloor and \lceil \log_b n \rceil respectively. Requires n \ge 1 and b \ge 2.

Returns \lceil \log_b 2^n \rceil. Requires b \ge 2.

Returns n with its lowest b bits in reverse order; for example the 6-bit number 010110_2 becomes 011010_2.

int n_sizeinbase(ulong n, int base)

Returns the number of digits of n in the given base (2 \le \mathit{base} \le 36); n_sizeinbase returns 1 for n = 0. n_nonzero_sizeinbase10 is a branch-free version for base 10 and requires n \ne 0.

Integer roots and perfect powers#

Returns \lfloor \sqrt a \rfloor. n_sqrtrem also sets *r to a - \lfloor \sqrt a \rfloor^2.

More

Returns 1 if x is a perfect square, otherwise 0.

More
ulong n_rootrem(ulong * remainder, ulong n, ulong root)

Returns r = \lfloor n^{1/k} \rfloor for k = \mathit{root}, or 0 if n or k is 0. n_rootrem also sets the remainder n - r^k.

ulong n_cbrtrem(ulong * remainder, ulong n)

Returns \lfloor n^{1/3} \rfloor; n_cbrtrem also sets the remainder.

More
double n_cbrt_estimate(double a)

Alternative cube root algorithms used by n_cbrt: a bit-manipulation estimate in the spirit of the fast inverse square root, a binary search, and a Chebyshev approximation (requires n \ne 0).

More

n_is_perfect_power235 returns whether n is a square, cube or fifth power. n_factor_power235 returns the root r and sets *exp to k \in \{2, 3, 5\} if n = r^k, and otherwise returns 0.

More

If n = r^k with k \ge 2, returns k and sets *root to r; otherwise returns 0. Both 0 and 1 count as squares. The k found is not necessarily the largest possible.

Division and remainder#

These functions compute a \bmod n (and possibly the quotient) from a precomputed approximation of 1/n, which is much faster than a hardware division when the same n is used repeatedly. The approximation is either a ulong (_preinv functions), a double (_precomp functions) or the data for Barrett or Lemire reduction. For a comparison of the methods see Choosing a method for modular arithmetic.

With a ulong inverse#

Returns the precomputed inverse of n \ne 0 used by all _preinv functions [GraMol2010]. n_preinvert_limb_prenorm is a faster version for normalised n (top bit set).

Full documentation

Returns a \bmod n. No restrictions on a; n \ne 0.

Full documentation
ulong n_divrem_preinv(ulong * q, ulong a, ulong n, ulong ninv, unsigned int norm)
ulong n_divrem_preinv_unnorm(ulong * q, ulong a, ulong n, ulong ninv, unsigned int norm)

Returns a \bmod n and sets *q to \lfloor a/n \rfloor. The last two variants take the number of leading zero bits of n as norm; n_divrem_preinv_unnorm requires \mathit{norm} > 0.

Full documentation

Returns the quotient \lfloor a/n \rfloor. No restrictions on a; n \ne 0.

Full documentation

Returns a \bmod n for the two-limb integer a = a_{hi} B + a_{lo}. No restrictions on a; n \ne 0.

Full documentation
ulong n_lll_mod_preinv(ulong a_hi, ulong a_mi, ulong a_lo, ulong n, ulong ninv)

Returns a \bmod n for the three-limb integer a = a_{hi} B^2 + a_{mi} B + a_{lo}. Requires a_{hi} < n.

Full documentation

Returns a \bmod n and sets *q to the quotient (0 or 1), assuming n is normalised. No inverse is needed: the quotient is a single comparison.

With a double inverse#

Returns 1/n as a double, the precomputed inverse used by all _precomp functions. Requires n > 0.

ulong n_mod_precomp(ulong a, ulong n, double ninv)

Returns a \bmod n. Requires n < 2^{53}, a < n^2 and a < 2^{\mathtt{FLINT\_BITS} - 1}.

More
ulong n_mod2_precomp(ulong a, ulong n, double ninv)

Returns a \bmod n with no restrictions on a or n.

More
ulong n_divrem2_precomp(ulong * q, ulong a, ulong n, double npre)

Returns a \bmod n and sets *q to the quotient. No restrictions on a or n.

Barrett and Lemire reduction#

Returns the precomputed inverse for n_mod_barrett. Requires n \ge 2.

Returns x \bmod n using Barrett reduction [Bar1987]. The lazy version returns a residue in [0, 2n) instead of [0, n). No restrictions on x. Both support n = 1 if npre is set to UWORD_MAX.

Returns the precomputed inverse for n_mod_lemire. Requires n \ge 1.

Returns x \bmod n using the method of Lemire, Kaser and Kurz [LKK2019]. Only correct for n, x < 2^{\mathtt{FLINT\_BITS} / 2}.

Divisibility#

int n_divides(ulong * q, ulong n, ulong p)

Returns 1 and sets *q to n/p if p divides n; otherwise returns 0 and sets *q to 0.

int n_divisible_odd_gm(ulong n, ulong inv1, ulong inv2)

Returns whether the odd number d divides n, given \mathit{inv1} = d^{-1} \bmod B and \mathit{inv2} = \lfloor (B - 1)/d \rfloor. Costs one multiplication. See Divisibility testing by multiplication.

int n_remove(ulong * n, ulong p)
int n_remove2_precomp(ulong * n, ulong p, double ppre)

Divides *n by the largest possible power of p > 1 and returns the exponent. Requires n \ne 0. n_remove2_precomp takes ppre = n_precompute_inverse(p).

More

Greatest common divisor#

Returns \gcd(x, y), with \gcd(x, 0) = \gcd(0, x) = x.

More
ulong n_xgcd(ulong * a, ulong * b, ulong x, ulong y)

Returns g = \gcd(x, y) and sets *a, *b to unsigned values with ax - by = g. Requires x \ge y.

More

Modular addition and inversion#

Returns (a + b) \bmod n, (a - b) \bmod n and -a \bmod n for reduced operands.

Returns x^{-1} \bmod y. Throws an exception if the inverse does not exist.

Returns g = \gcd(x, y) and sets *a to the 0 \le a < y with ax \equiv g \pmod y. Requires x < y. When y = 1, returns 1 and sets *a to 0.

Returns the inverse of odd n modulo B; the result is meaningless for even n.

More

Modular multiplication#

Returns ab \bmod n. No restrictions on a, b or n.

Full documentation

Returns ab \bmod n, computing the inverse of n on the fly. Use n_mulmod2_preinv when n is reused.

Full documentation

Returns \lfloor a / 2^{\mathit{norm}} \rfloor \, b \bmod n for normalised n and reduced a, b. If a, b and n are the operands and modulus shifted left by norm bits, this is their product modulo the unshifted modulus, shifted left by norm bits.

Full documentation
ulong n_mulmod_precomp(ulong a, ulong b, ulong n, double ninv)

Returns ab \bmod n. Requires n < 2^{53} and a, b < n.

More

Multiplication by a fixed operand#

These functions speed up computing a b_i \bmod n for fixed a and n and many b_i, as in scalar multiplication of vectors and matrices [Sho2021; Har2014]. They require n < 2^{\mathtt{FLINT\_BITS} - 1}.

Returns \lfloor a B / n \rfloor, the precomputed data for n_mulmod_shoup. Requires a < n.

Full documentation

Returns ab \bmod n given a_precomp from n_mulmod_precomp_shoup. Requires a < n; b is arbitrary.

Full documentation
void n_mulmod_precomp_shoup_quo_rem(ulong * a_pr_quo, ulong * a_pr_rem, ulong a, ulong n)

Compute both the quotient \lfloor aB/n \rfloor and the remainder aB \bmod n, as needed by n_mulmod_and_precomp_shoup. The second function recovers the remainder from a known quotient.

Full documentation
void n_mulmod_and_precomp_shoup(ulong * ab, ulong * ab_precomp, ulong a, ulong b, ulong a_pr_quo, ulong a_pr_rem, ulong b_precomp, ulong n)

Sets *ab to ab \bmod n and *ab_precomp to its precomputed data \lfloor (ab \bmod n) B / n \rfloor, without a division. Requires a, b < n. Useful for building tables of powers a, a^2, a^3, \ldots together with their precomputed data.

Full documentation

Modular exponentiation#

Returns a^{\mathit{exp}} \bmod n for a < n. Negative exponents are allowed; an exception is thrown if a is then not invertible.

Full documentation

Returns a^{\mathit{exp}} \bmod n for an unsigned exponent and a < n. n_powmod_ui_preinv requires normalised n, like n_mulmod_preinv.

Full documentation

Returns a^{\mathit{exp}} \bmod n for a nonnegative multiprecision exponent and a < n.

Full documentation
ulong n_powmod_precomp(ulong a, slong exp, ulong n, double npre)
ulong n_powmod_ui_precomp(ulong a, ulong exp, ulong n, double npre)

Returns a^{\mathit{exp}} \bmod n using a double inverse. Require n < 2^{53} and a < n.

Chinese remaindering#

ulong n_CRT(ulong r1, ulong m1, ulong r2, ulong m2)

Returns the unique 0 \le x < m_1 m_2 with x \equiv r_1 \pmod{m_1} and x \equiv r_2 \pmod{m_2}. Requires coprime m_1, m_2 > 1 with m_1 m_2 fitting in a ulong, and reduced r_1, r_2. Nothing is checked.

Jacobi symbols#

int n_jacobi(slong x, ulong y)

Returns the Jacobi symbol \left(\frac{x}{y}\right) for odd y (not checked), with a binary algorithm [ShaSor1993]. n_jacobi_unsigned accepts a full-limb x.

Primes#

Finding, counting and enumerating primes. To run through consecutive primes, use a prime iterator (n_primes_t); the first primes and their inverses are also available from a per-thread cache.

ulong n_nextprime(ulong n, int proved)

Returns the smallest prime greater than n. Throws an exception if it does not fit in a ulong. The flag proved has no effect: the result is always a proved prime.

void n_prime_pi_bounds(ulong * lo, ulong * hi, ulong n)

Return the number \pi(n) of primes p \le n, or set \mathit{lo} \le \pi(n) \le \mathit{hi}.

More
void n_nth_prime_bounds(ulong * lo, ulong * hi, ulong n)

Return the n-th prime p_n (with p_1 = 2; n = 0 throws an exception), or set \mathit{lo} \le p_n \le \mathit{hi}.

More
void n_primes_init(n_primes_t iter)
void n_primes_clear(n_primes_t iter)

Initialise and clear a prime iterator.

ulong n_primes_next(n_primes_t iter)

Returns the next prime and advances the iterator. The first call returns 2.

More
void n_primes_jump_after(n_primes_t iter, ulong n)

Makes the iterator continue with the first prime greater than n.

void n_compute_primes(ulong num_primes)
const ulong * n_primes_arr_readonly(ulong num_primes)
void n_cleanup_primes(void)

Maintain a per-thread cache of the first primes and their double inverses. The _readonly functions return pointers into the cache, which stay valid until n_cleanup_primes is called in the same thread.

void n_primes_extend_small(n_primes_t iter, ulong bound)
void n_primes_sieve_range(n_primes_t iter, ulong a, ulong b)

Internal helpers of the prime iterator: extend its table of small primes until the second-largest entry is at least bound, or sieve the odd numbers in [a, b] and point the iterator at the start of that block.

Primality testing#

n_is_prime, and n_ll_is_prime for two-limb integers, are the functions to use. The others are individual probable prime tests and two alternative primality proofs, of interest mainly for testing and experiments.

OverviewPrimality testing for word-size integersHow n_is_prime proves primality of any 64-bit integer with at most two strong probable prime tests, using table lookups, vectorised trial division and a hashed table of witnesses.

Returns 1 if n is prime and 0 otherwise. Deterministic for all n.

Full documentation

Like n_is_prime for odd n, but skips trial division. Faster when n is already known to have no small factors.

Full documentation
int n_ll_is_prime(ulong nhi, ulong nlo)

Primality test for the two-limb integer n = n_{hi} B + n_{lo} with n_{hi} \ne 0. Returns 1 (prime), 0 (composite) or -1 (unknown). The answer is always definite below about 2^{81} on 64-bit machines.

More

Test whether odd n is a strong probable prime to base a [Mil1976; Rab1980], given the odd part d of n - 1 and 0 < a < n. The _precomp version requires n < 2^{53}. See Strong probable prime test.

Returns whether i^{n-1} \equiv 1 \pmod n. Requires 1 < i < n and i \nmid n.

Fibonacci probable prime test: checks F_{n - (n/5)} \equiv 0 \pmod n, where (n/5) is a Jacobi symbol [CraPom2005]. Requires \gcd(n, 10) = 1.

Lucas probable prime test, similar to the one of Baillie and Wagstaff [BaiWag1980].

Baillie–PSW probable prime test [PSW1980; BaiWag1980]. No composite passing it is known, and it has been checked against tables of pseudoprimes up to 2^{64}, so it is a primality test for word-size n.

More

Pocklington–Lehmer test [Poc1914; BLS1975]. Returns 1 if n is proved prime, 0 if it is composite, and -1 if nothing was proved because the bases 2, \ldots, \mathit{iterations} - 1 were not enough. If \mathit{iterations} is 0 or 1, the number of bases is not limited and -1 is never returned for this reason.

More

Primality test based on pseudosquares, following Theorem 2.7 of [LukPatWil1996].

More

Obsolete; calls n_is_prime.

Factoring#

OverviewFactoring word-size integersHow n_factor combines trial division, primality testing, perfect power detection, Pollard–Brent rho, Hart's one-line method and SQUFOF to factor any 64-bit integer.

A factorisation p_1^{e_1} \cdots p_k^{e_k} into distinct primes, with fields num (the number k of distinct primes), p[] (the primes) and exp[] (the exponents).

Full documentation
void n_factor_init(n_factor_t * factors)

Initialises factors to the empty factorisation.

Full documentation
void n_factor(n_factor_t * factors, ulong n, int proved)

Sets factors to the complete factorisation of n (empty for n \le 1); factors need not be initialised. The flag proved has no effect, as all primality tests used are deterministic for word-size integers.

Full documentation

Returns p_1^{e_1} \cdots p_k^{e_k}, or 0 if it does not fit in a ulong.

void n_factor_insert(n_factor_t * factors, ulong p, ulong exp)

Multiplies the factorisation by p^{\mathit{exp}}, adding to the exponent of p if it is already present.

ulong n_factor_trial(n_factor_t * factors, ulong n, ulong num_primes)
ulong n_factor_trial_range(n_factor_t * factors, ulong n, ulong start, ulong num_primes)

Trial division by the first num_primes primes (starting at the prime with index start). Factors found are added to factors, which must be initialised; the unfactored cofactor is returned.

More
ulong n_factor_trial_partial(n_factor_t * factors, ulong n, ulong * prod, ulong num_primes, ulong limit)
ulong n_factor_partial(n_factor_t * factors, ulong n, ulong limit, int proved)

Partial factorisation: like n_factor_trial and n_factor, but stop as soon as the product of the prime factors found exceeds limit. Return the cofactor; n_factor_trial_partial also sets *prod to the product of the factors found.

Hart's one-line factoring algorithm [Har2012], a variant of Fermat's method. Returns a factor of n or 0. Faster than SQUFOF below about 2^{40}.

Lehman's algorithm [Leh1974]. Always returns a factor of n, but works only up to 10^{16} and is not used by n_factor.

Shanks' square form factorisation as described by Gower and Wagstaff [GowWag2008]. Returns a factor of n that fits in one limb, or 0 if none was found within iters iterations. The ll version takes a two-limb n = n_{hi} B + n_{lo}.

More

Williams' p + 1 method [Wil1982] with prime bound B_1 and a random starting value 2 < c < n. Returns a factor, or 0 or 1 on failure. The wrapper chooses parameters tuned for 31 to 64-bit n.

More
int n_factor_pollard_brent_single(ulong * factor, ulong n, ulong ai, ulong xi, ulong max_iters)
int n_factor_pollard_brent(ulong * factor, flint_rand_t state, ulong n_in, ulong max_tries, ulong max_iters)

Pollard's rho method [Pol1975] with Brent's cycle detection [Bre1980], for composite n. Return 1 and set *factor to a nontrivial (not necessarily prime) factor on success, otherwise 0. The first function uses the polynomial x^2 + a_i and starting value x_i; the second tries up to max_tries random choices.

int n_ll_factor_rho(nn_ptr factor, ulong nhi, ulong nlo, ulong max_tries, ulong max_iters)

Pollard–Brent rho for an odd two-limb n with n_{hi} \ne 0. Returns 1 and writes a nontrivial two-limb factor on success, otherwise 0.

More
int n_ll_factor_ecm(nn_ptr factor, ulong nhi, ulong nlo, ulong curves, ulong B1, ulong B2, flint_rand_t state)

The elliptic curve method for an odd two-limb n with n_{hi} \ne 0, trying up to curves curves with bounds B_1, B_2 (if B_2 < B_1, then 100 B_1 is used). Returns 1 and writes a factor on success, otherwise 0.

More
int n_factor_ecm(ulong * f, ulong curves, ulong B1, ulong B2, flint_rand_t state, ulong n)

The elliptic curve method [Len1987; ZD2006] for a single-limb n, trying up to curves random curves with stage bounds B_1 and B_2. Returns 1 or 2 if a factor was found in stage I or II, -1 if one was found while selecting a curve, and 0 on failure. The factor is stored in *f.

Arithmetic functions#

void n_moebius_mu_vec(int * mu, ulong len)

Compute the Möbius function \mu(n), with \mu(0) = 0, or the values \mu(0), \ldots, \mu(\mathit{len} - 1).

More

Returns whether n is squarefree, that is, \mu(n) \ne 0. By convention 1 is squarefree and 0 is not.

Returns Euler's totient \varphi(n), the number of 1 \le k \le n coprime to n.

Factorials#

Return n! \bmod p for any modulus p (no optimisations for composite p). The fast version uses fast multipoint evaluation in about O(n^{1/2}) operations up to logarithmic factors [Pol1974; BGS2007]; the other chooses between table lookup, a direct product and the fast algorithm depending on n.

Square roots modulo n#

Returns the square root of a modulo the prime p that lies in [0, p/2], or 0 if a is not a square. Requires a < p.

More

Compute all square roots of a modulo 2^{\mathit{exp}}, modulo p^{\mathit{exp}}, or modulo an integer m given by its factorisation, and return their number. The roots are written to a newly allocated array stored in *sqrt, which the caller frees with flint_free. If a is not a square, 0 is returned and *sqrt is set to NULL.

Primitive roots and discrete logarithms#

For odd non-square n, returns some a with Jacobi symbol \left(\frac{a}{n}\right) = -1; for prime n this is a quadratic nonresidue.

Return a primitive root modulo the prime p. The prefactor version takes the prime factors q of p - 1 (exponents are ignored) and returns an a with a^{(p-1)/q} \ne 1 for every q given.

Returns x with a^x \equiv b \pmod n by baby-step giant-step [Sha1971], assuming (\mathbb{Z}/n\mathbb{Z})^\times is cyclic, that is, n is 2, 4, p^k or 2p^k for an odd prime p.

Random numbers#

All functions draw from a flint_rand_t state. Those with randtest in the name make corner cases such as 0, 1 and values with few set bits more likely, and are meant for test code.

Returns a uniformly random limb. _n_randlimb is an inline version for tight loops.

More
ulong n_randbits(flint_rand_t state, unsigned int bits)

Returns a uniformly random integer with exactly bits bits (the top bit is set), or 0 if bits is 0.

Like n_randbits, but values with sparse binary representations are more likely.

Returns a uniformly random integer in [0, \mathit{limit}), or a random limb if limit is 0. The three functions are equivalent; _n_randint is inline.

Returns a random integer of random bit length between 0 and FLINT_BITS, with 0, 1, COEFF_MAX, WORD_MAX, UWORD_MAX and sparse values made more likely.

Like n_randtest, but never returns 0.

ulong n_randprime(flint_rand_t state, ulong bits, int proved)

Returns a random prime with exactly bits bits, where 2 \le \mathit{bits} \le \mathtt{FLINT\_BITS}. The result is always a proved prime; the flag proved has no effect.

Returns a random prime whose bit length is chosen at random between 2 and FLINT_BITS.

Double-limb modular exponentiation#

Low-level helpers for the base-2 and small-base strong probable prime tests in n_ll_is_prime. The modulus m has two limbs (m > B) but must be below roughly 2^{3 \mathtt{FLINT\_BITS} / 2}.

Computes the two-limb inverse \lfloor 2^{3 \mathtt{FLINT\_BITS}} / m \rfloor of a two-limb m > B, as needed by n_ll_small_2_powmod and n_ll_small_powmod_triple.

void n_ll_small_powmod_triple(nn_ptr res1, nn_ptr res2, nn_ptr res3, ulong b1, ulong b2, ulong b3, nn_srcptr exp, nn_srcptr m, nn_srcptr minv)

Compute b^e \bmod m for small single-limb bases b and two-limb e and m > B: the first function for b = 2, the second for three bases b_1 \le b_2 \le b_3 at once. Helpers for n_ll_is_prime.

More

ECM internals#

Building blocks of n_factor_ecm. Points are in Montgomery projective coordinates (x : z) on curves in Montgomery form [Mon1987], and arithmetic is modulo n using the parameters stored in n_ecm_inf.

void n_factor_ecm_double(ulong * x, ulong * z, ulong x0, ulong z0, ulong n, n_ecm_t n_ecm_inf)

Sets (x : z) = 2 (x_0 : z_0), using x = (x_0 + z_0)^2 (x_0 - z_0)^2 and z = 4 x_0 z_0 \left((x_0 - z_0)^2 + 4 a_{24} x_0 z_0\right).

void n_factor_ecm_add(ulong * x, ulong * z, ulong x1, ulong z1, ulong x2, ulong z2, ulong x0, ulong z0, ulong n, n_ecm_t n_ecm_inf)

Sets (x : z) = (x_1 : z_1) + (x_2 : z_2) given their difference (x_0 : z_0).

void n_factor_ecm_mul_montgomery_ladder(ulong * x, ulong * z, ulong x0, ulong z0, ulong k, ulong n, n_ecm_t n_ecm_inf)

Sets (x : z) = k (x_0 : z_0) with the Montgomery ladder.

int n_factor_ecm_select_curve(ulong * f, ulong sigma, ulong n, n_ecm_t n_ecm_inf)

Selects a curve and starting point from sigma with Suyama's parametrisation, storing x_0, z_0 and (a + 2)/4 in n_ecm_inf. Returns 1 if a factor of n turned up along the way (stored in *f), otherwise 0.

int n_factor_ecm_stage_I(ulong * f, const ulong * prime_array, ulong num, ulong B1, ulong n, n_ecm_t n_ecm_inf)
int n_factor_ecm_stage_II(ulong * f, ulong B1, ulong B2, ulong P, ulong n, n_ecm_t n_ecm_inf)

Stage I with the num primes up to B_1 in prime_array, and stage II up to B_2 with primorial P \approx \sqrt{B_2}. Return 1 and set *f if a factor is found, otherwise 0.

References#

  • [GraMol2010] N. Möller and T. Granlund, "Improved division by invariant integers", IEEE Transactions on Computers 60 (2011), 165–175, https://gmplib.org/~tege/division-paper.pdf
  • [Bar1987] P. Barrett, "Implementing the Rivest Shamir and Adleman public key encryption algorithm on a standard digital signal processor", Advances in Cryptology – CRYPTO '86, LNCS 263 (1987), 311–323
  • [LKK2019] D. Lemire, O. Kaser and N. Kurz, "Faster remainder by direct computation: applications to compilers and software libraries", Software: Practice and Experience 49 (2019), 953–970, https://arxiv.org/abs/1902.01961
  • [Sho2021] V. Shoup, "Arithmetic software libraries", chapter 9 of Computational Cryptography, Cambridge University Press (2021), https://doi.org/10.1017/9781108854207.012
  • [Har2014] D. Harvey, "Faster arithmetic for number-theoretic transforms", Journal of Symbolic Computation 60 (2014), 113–119, https://doi.org/10.1016/j.jsc.2013.09.002
  • [ShaSor1993] J. Shallit and J. Sorenson, "A binary algorithm for the Jacobi symbol", ACM SIGSAM Bulletin 27 (1993), 4–11
  • [Mil1976] G. L. Miller, "Riemann's hypothesis and tests for primality", Journal of Computer and System Sciences 13 (1976), 300–317
  • [Rab1980] M. O. Rabin, "Probabilistic algorithm for testing primality", Journal of Number Theory 12 (1980), 128–138
  • [CraPom2005] R. Crandall and C. Pomerance, Prime Numbers: A Computational Perspective, second edition, Springer (2005).
  • [BaiWag1980] Robert Baillie; Samuel S. Wagstaff, Jr. (October 1980). "Lucas Pseudoprimes". Mathematics of Computation. 35 (152): 1391–1417.
  • [PSW1980] C. Pomerance, J. L. Selfridge and S. S. Wagstaff, Jr., "The pseudoprimes to 25·10^9", Mathematics of Computation 35 (1980), 1003–1026
  • [Poc1914] H. C. Pocklington, "The determination of the prime or composite nature of large numbers by Fermat's theorem", Proceedings of the Cambridge Philosophical Society 18 (1914), 29–30
  • [BLS1975] J. Brillhart, D. H. Lehmer and J. L. Selfridge, "New primality criteria and factorizations of 2^m ± 1", Mathematics of Computation 29 (1975), 620–647
  • [LukPatWil1996] R. F. Lukes and C. D. Patterson and H. C. Williams "Some results on pseudosquares" Math. Comp. 1996, no. 65, 361–372
  • [Har2012] Hart, William B.. (2012) A one line factoring algorithm. Journal of the Australian Mathematical Society, Volume 92 (Number 1). pp. 61-69.
  • [Leh1974] R. S. Lehman, "Factoring large integers", Mathematics of Computation 28 (1974), 637–646
  • [GowWag2008] Jason Gower and Sam Wagstaff : "Square form factoring" Math. Comp. 77, 2008, pp 551-588, https://doi.org/10.1090/S0025-5718-07-02010-8
  • [Wil1982] H. C. Williams, "A p+1 method of factoring", Mathematics of Computation 39 (1982), 225–234
  • [Pol1975] J. M. Pollard, "A Monte Carlo method for factorization", BIT 15 (1975), 331–334
  • [Bre1980] R. P. Brent, "An improved Monte Carlo factorization algorithm", BIT 20 (1980), 176–184
  • [Len1987] H. W. Lenstra, Jr., "Factoring integers with elliptic curves", Annals of Mathematics 126 (1987), 649–673
  • [ZD2006] P. Zimmermann and B. Dodson, "20 years of ECM", Algorithmic Number Theory (ANTS VII), LNCS 4076 (2006), 525–542
  • [Pol1974] J. M. Pollard, "Theorems on factorization and primality testing", Proceedings of the Cambridge Philosophical Society 76 (1974), 521–528
  • [BGS2007] A. Bostan, P. Gaudry and É. Schost, "Linear recurrences with polynomial coefficients and application to integer factorization and Cartier–Manin operator", SIAM Journal on Computing 36 (2007), 1777–1806
  • [Sha1971] D. Shanks, "Class number, a theory of factorization, and genera", Proc. Symp. Pure Math. 20, American Mathematical Society (1971), 415–440
  • [Mon1987] P. L. Montgomery, "Speeding the Pollard and elliptic curve methods of factorization", Mathematics of Computation 48 (1987), 243-264, https://doi.org/10.1090/S0025-5718-1987-0866113-7
Cite this page

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