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
- Choose a smoothness bound B1 and a base a, commonly 2.
- Set M ← ∏ q⌊logq B1⌋ over primes q ≤ B1. M is divisible by every B1-smooth number.
- Compute x ← aM mod n, accumulating the exponent prime by prime rather than forming M explicitly.
- Set g ← gcd(x − 1, n).
- 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.
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.
- Let x be the stage-one result aM mod n.
- Precompute xd for the small gaps d between consecutive primes in (B1, B2]. Gaps are small and repeat, so the table is short.
- Step through the primes q in that range, updating xq by one table multiplication each.
- Accumulate the product of (xq − 1) over a batch and take a single GCD per batch.
- Return any non-trivial GCD found.
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
| Method | Succeeds when | Arithmetic |
|---|---|---|
| p − 1 (Pollard) | p − 1 is smooth | Modular exponentiation |
| p + 1 (Williams) | p + 1 is smooth | Lucas sequences |
| Cyclotomic variants | Φk(p) is smooth for small k | Arithmetic in higher extensions |
| ECM (Lenstra) | Some curve order near p is smooth — resamplable | Elliptic curve group law |
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.
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.
