Algorithm Search⌘K

Proofs: Pollard's p-1 algorithm

These are the human proofs of Pollard's p-1 algorithm, at full length.

Correctness of Pollard's p-1 algorithm full

This proof shows: correctness, termination.

Let N≥3N \ge 3, B≥1B \ge 1 and 2≤a<N2 \le a < N. Write M(B)=lcm⁡(1,2,…,B)M(B) = \operatorname{lcm}(1, 2, \dots, B).

Lemma 1. M(B)=∏q≤BqeqM(B) = \prod_{q \le B} q^{e_q}, where qq runs over the primes at most BB and eqe_q is the largest integer with qeq≤Bq^{e_q} \le B.

Proof. Let PP be the product on the right. For each k≤Bk \le B and each prime power qj∥kq^j \parallel k, we have q≤qj≤k≤Bq \le q^j \le k \le B and j≤eqj \le e_q, so k∣Pk \mid P. So PP is a common multiple of 1,…,B1, \dots, B. Conversely each factor qeq≤Bq^{e_q} \le B is one of the numbers 1,…,B1, \dots, B, so qeqq^{e_q} divides every common multiple, and these factors are pairwise coprime, so PP divides every common multiple. Hence PP is the least common multiple. □\square

Invariant. Let q1<q2<⋯<qmq_1 < q_2 < \cdots < q_m be the primes at most BB. After ii passes of the loop of lines L2 to L4, c≡aq1e1⋯qiei(modN)c \equiv a^{q_1^{e_1} \cdots q_i^{e_i}} \pmod N.

Proof. Before the loop, c=ac = a, which is the empty product case i=0i = 0. If the claim holds after ii passes, line L3 computes e=ei+1e = e_{i+1} and line L4 replaces cc by cqi+1ei+1 mod Nc^{q_{i+1}^{e_{i+1}}} \bmod N, which is congruent to aq1e1⋯qi+1ei+1a^{q_1^{e_1} \cdots q_{i+1}^{e_{i+1}}}. □\square

Termination. The loop runs once for each of the m=π(B)m = \pi(B) primes, line L3 is a finite loop because q≥2q \ge 2, and line L4 is a modular exponentiation with a finite exponent. So the algorithm stops.

The output. By the invariant and Lemma 1, c≡aM(B)(modN)c \equiv a^{M(B)} \pmod N after the loop, so line L5 returns g=gcd⁡(aM(B)−1,N)g = \gcd(a^{M(B)} - 1, N), which is a positive divisor of NN (if c=1c = 1, then c−1=0c - 1 = 0 and g=Ng = N).

Theorem. (a) Let pp be a prime factor of NN with p∤ap \nmid a, and suppose that every prime power that divides p−1p - 1 is at most BB. Then p∣gp \mid g.

(b) Let rkr^k be the exact power of a prime rr that divides NN. If aM(B)≢1(modrk)a^{M(B)} \not\equiv 1 \pmod{r^k}, then rk∤gr^k \nmid g, so g<Ng < N.

(c) If the hypotheses of (a) and (b) both hold, then 1<g<N1 < g < N and gg is a proper factor of NN.

Proof. (a) Every prime power qj∥p−1q^j \parallel p - 1 has qj≤Bq^j \le B, so j≤eqj \le e_q and qj∣M(B)q^j \mid M(B) by Lemma 1. These prime powers are pairwise coprime, so p−1∣M(B)p - 1 \mid M(B). By Fermat's little theorem, ap−1≡1(modp)a^{p - 1} \equiv 1 \pmod p, so aM(B)≡1(modp)a^{M(B)} \equiv 1 \pmod p, and pp divides aM(B)−1a^{M(B)} - 1 and NN, so p∣gp \mid g.

(b) If rk∣gr^k \mid g, then rk∣aM(B)−1r^k \mid a^{M(B)} - 1, against the hypothesis. Since rk∣Nr^k \mid N and rk∤gr^k \nmid g, g≠Ng \ne N.

(c) By (a), g≥p>1g \ge p > 1, and by (b), g<Ng < N. ■\blacksquare

Back to Pollard's p-1 algorithm