The elliptic curve method
- Cost
- Heuristically multiplications modulo to find a prime factor .
The elliptic curve method (ECM) of Lenstra [Len1987] finds a prime factor of in a time that depends mainly on the size of . It is the method of choice for factors of 20 to 40 digits in numbers too large for the quadratic sieve, and fmpz_factor runs it before the sieve to remove medium-sized factors. The implementation follows Montgomery [Mon1987] and Zimmermann and Dodson [ZD2006].
The idea#
Pollard's method computes for a highly composite exponent , and finds if the order of modulo , a divisor of , divides . It thus succeeds only if is smooth. ECM replaces the multiplicative group of by the group of points of an elliptic curve over . By Hasse's theorem [Sil2009, Theorem V.1.1] its order lies in , and as the curve varies the order is distributed over this interval roughly like a random integer of that size. Trying many curves gives many independent chances of a smooth group order.
One computes with a curve and a point defined modulo , as if were a field. In projective coordinates, a multiple is a point ; if the order of modulo divides , then is the point at infinity modulo , so divides and reveals , unless the same happens modulo all prime factors of at once, which is unlikely.
Montgomery curves#
FLINT uses curves in Montgomery form and represents a point by its -coordinate in projective form , which identifies and but suffices for scalar multiplication. With , the doubling and the differential addition (which needs the difference of the two points) are
about ten multiplications modulo for a doubling and an addition together, and no inversion. The Montgomery ladder computes by keeping the pair , whose difference is always , and replacing it by or for each bit of .
Curves are chosen by Suyama's parametrisation [Suy1985; ZD2006]: for a random , put , , the starting point and . The group order of these curves is divisible by 12, which increases the probability that it is smooth. The inversion needed for may itself reveal a factor of .
Stage 1#
Input: , a curve and a point modulo , a bound .
Output: a factor of , or the point with .
- For each prime , replace by with the Montgomery ladder, and if , return the GCD.
- Return .
If the order of the starting point modulo is -smooth (a product of prime powers at most ), it divides and stage 1 finds . The cost is about ladder steps. FLINT takes the GCD after every prime, which costs little since is small in its applications.
Stage 2#
Often the order of is -smooth except for one larger prime with . Stage 2 tests all these primes at once with the standard continuation. Choose a primorial (the product of the first few primes) close to ; every prime in can be written with and .
Lemma 1. Let be a point modulo a prime and . If , then , that is, .
Proof. means , and for every point , since the -coordinate does not distinguish a point from its negative.
Input: , the point from stage 1, bounds , the primorial .
Output: a factor of or failure.
- Compute for all odd (by differential additions of ), and .
- . For from about to about (computing by differential additions of ): for each with such that or is prime, set .
- Return if it is a nontrivial factor.
By Lemma 1, if the order of modulo is a prime in , then . The cost is about point operations and three multiplications per prime , and a single GCD. Asymptotically faster versions of stage 2, using fast polynomial arithmetic [ZD2006], are not implemented.
Parameters and complexity#
The probability that a random integer near is -smooth is heuristically . Taking balances the cost of a curve against the number of curves needed, for a total of operations modulo [Len1987]. In practice the parameters are tuned experimentally: fmpz_factor_smooth uses and the values of and of the number of curves shown on Factoring integers, which find a factor of the given size with probability about per size class. For example, to find a factor of 40 bits it runs 18 curves with , and for 60 bits 42 curves with .
Use in FLINT#
fmpz_factor_ecmfor multiprecision , with the arithmetic modulo done byflint_mpn_mulmod_preinvnon normalised limb arrays. The curves are distributed over the available threads; the factor returned is the one found by the curve of lowest index, so the result does not depend on the number of threads.n_factor_ecmfor one-word andn_ll_factor_ecmfor two-word , with the same curves and stages in word arithmetic.fmpz_factor_smoothandfmpz_factor, which callfmpz_factor_ecmwith the tuned parameters.
The stages are exposed as fmpz_factor_ecm_select_curve, fmpz_factor_ecm_stage_I and fmpz_factor_ecm_stage_II.
int fmpz_factor_ecm(fmpz_t f, ulong curves, ulong B1, ulong B2, flint_rand_t state, const fmpz_t n_in)int n_factor_ecm(ulong * f, ulong curves, ulong B1, ulong B2, flint_rand_t state, ulong n)int n_ll_factor_ecm(nn_ptr factor, ulong nhi, ulong nlo, ulong curves, ulong B1, ulong B2, flint_rand_t state)int fmpz_factor_smooth(fmpz_factor_t factor, const fmpz_t n, slong bits, int proved)Referenced from#
- Factoring integers (overview)
- The quadratic sieve (algorithm)
fmpz_factor_ecm
References#
- [Len1987] H. W. Lenstra, Jr., "Factoring integers with elliptic curves", Annals of Mathematics 126 (1987), 649–673
- [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
- [ZD2006] P. Zimmermann and B. Dodson, "20 years of ECM", Algorithmic Number Theory (ANTS VII), LNCS 4076 (2006), 525–542
- [Sil2009] J. H. Silverman, The Arithmetic of Elliptic Curves, 2nd edition, Graduate Texts in Mathematics 106, Springer (2009)
- [Suy1985] H. Suyama. Informal preliminary report (8). Letter to R. P. Brent, 1985.
The FLINT team, “The elliptic curve method,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/number-theory/ecm.html (generated 2026-11-02).
@misc{flint-doc-algorithms-number-theory-ecm,
author = {{The FLINT team}},
title = {{The elliptic curve method}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/number-theory/ecm.html},
note = {Generated 2026-11-02}
}