← LibraryPollard's p−1 Method and Its RelativesEngineering · MathematicsLesson 4/8← PrevNext →
GuidePublished 6 Aug 20264 min readBy Kevin JoginComputational Number TheoryFactoringPollard P-1P+1 Method
Skip to the main content

MathematicsFactoring

Pollard's p−1 Method and Its Relatives

Exploiting a factor whose group order happens to be smooth — and the p+1 and Williams variants that widen the target.

Executive summary

A special-purpose method that is nearly free to try

If p − 1 is smooth, then for a suitable exponent M built from small prime powers, aM ≡ 1 (mod p) by Fermat, so gcd(aM − 1, n) reveals p. The method succeeds only for factors with this special property, but it costs little to attempt and is therefore standard in every pipeline. Its failure against deliberately chosen primes is exactly what motivated ECM.

Learning objectives

  • State the smoothness condition the method requires.
  • Implement both stages and explain what the second stage adds.
  • Describe the p+1 variant and when it applies.
  • Explain the implications for cryptographic prime selection.
  • Position the method relative to ECM.

Section 01The first stage

AlgorithmPollard p−1, stage onein: n, bound B1  →  out: a factor p with p−1 B1-smooth
  1. Choose a smoothness bound B1 and a base a, commonly 2.
  2. Set M ← ∏ q⌊logq B1 over primes q ≤ B1. M is divisible by every B1-smooth number.
  3. Compute x ← aM mod n, accumulating the exponent prime by prime rather than forming M explicitly.
  4. Set g ← gcd(x − 1, n).
  5. If 1 < g < n, return g. If g = 1, increase B1 or go to stage two. If g = n, back off and retry with a smaller exponent.
Cost is one long modular exponentiation, about B1 modular multiplications. Cheap enough to run speculatively on every composite.
The g = n case

If every prime factor of n has smooth order, the GCD returns n and no information. Restart with a smaller bound, or take GCDs more frequently during the exponentiation so the factors are separated before both are absorbed.

Section 02The second stage

Stage two handles the common case where p − 1 is B1-smooth except for a single larger prime factor q between B1 and a second bound B2.

AlgorithmStage two (standard continuation)in: stage-one result, bounds B1, B2  →  out: a factor
  1. Let x be the stage-one result aM mod n.
  2. Precompute xd for the small gaps d between consecutive primes in (B1, B2]. Gaps are small and repeat, so the table is short.
  3. Step through the primes q in that range, updating xq by one table multiplication each.
  4. Accumulate the product of (xq − 1) over a batch and take a single GCD per batch.
  5. Return any non-trivial GCD found.
B2 is typically 50 to 100 times B1. Stage two costs one multiplication per prime rather than one exponentiation, so the extended range is nearly free.
The same two-stage structure appears in ECM

Stage one raises to a smooth exponent; stage two sweeps a range for one remaining large prime. ECM uses exactly this structure on an elliptic curve group, which is why the two implementations share so much code.

Section 03The p+1 method and variants

Related special-purpose methods
MethodSucceeds whenArithmetic
p − 1 (Pollard)p − 1 is smoothModular exponentiation
p + 1 (Williams)p + 1 is smoothLucas sequences
Cyclotomic variantsΦk(p) is smooth for small kArithmetic in higher extensions
ECM (Lenstra)Some curve order near p is smooth — resamplableElliptic curve group law
Why the p+1 method needs a parameter search

The Lucas sequence works in the norm-one subgroup of a quadratic extension, whose order is p + 1 only when the discriminant is a non-residue modulo p — which is unknown in advance. Several parameters must be tried, half of which land in the p − 1 case instead.

Section 04Consequences for prime selection

Because the method succeeds precisely when p − 1 is smooth, cryptographic primes are chosen so that it is not. A safe prime has p = 2q + 1 with q prime, making p − 1 maximally non-smooth.

A defence against one method only

Choosing safe primes defeats p−1 and p+1 completely, and defeats ECM not at all — ECM's group order varies with the curve and does not depend on p ± 1. Resistance to special-purpose methods must not be confused with resistance to general-purpose ones.

ReferenceFrequently asked questions

How should the bounds be chosen?

B1 sets the smoothness threshold and the cost of stage one; B2 extends the reach for one additional prime. Standard practice is to start with modest bounds, run the method as a cheap speculative stage, and escalate only if the structure of the problem suggests smoothness is likely.

Does the method work when n has several smooth factors?

It finds them all at once, returning n and thus nothing useful. Taking GCDs at intervals during the exponentiation separates the factors, because the first one to satisfy the condition is caught before the others do.

Is p-1 obsolete now that ECM exists?

No. It is far cheaper per attempt, and when p−1 happens to be smooth it succeeds immediately where ECM would need many curves. It costs one exponentiation to try, so it remains a standard early stage.

NavigateContinue in this stream

Curated next steps from this page. The site also surfaces algorithmically related reading below.

ProvenanceSources and further reading

This page is an original KEVOS explanatory article. It presents the underlying mathematics — definitions, algorithms, complexity results and selection criteria — in KEVOS editorial voice. No text is reproduced from any copyrighted source. Where numerical tables are relevant, KEVOS links to live authoritative databases rather than republishing static values.

Page ID
KV-MATH-0052
Taxonomy
ENG-MATH — Engineering / Mathematics
Collection
COL-CANT-001
Topic stream
CANT-FACTORING
Version
1.1.0 / content 2026.08
Last reviewed
2026-08-06

Continue learning

Shanks's SQUFOF Factoring MethodGuide · MathematicsNEXT LESSON →The Continued Fraction Factoring MethodGuide · MathematicsPollard's Rho Factoring MethodGuide · MathematicsThe Elliptic Curve Method (ECM)Guide · Mathematics