Note: Due to changes in the Riesel prime template, most of those pages (and related) are not shown properly.This will take some time!Wanna help? Please move any Riesel prime page first, then edit/add the base parameter.
 Topics Register • News • History • How to • Sequences statistics • Template prototypes

P-1 factorization method

P-1 is a factorization method invented by John Pollard in 1974.

It is based in the Fermat's Little Theorem that states that:

Let p be a prime which does not divide the integer a, then $\displaystyle{ a^{p-1}\equiv 1 \mbox{( mod } p) }$.

From the previous congruence we also get:

$\displaystyle{ a^{k(p-1)}\equiv 1 }$, where k is a non-negative integer. This means that $\displaystyle{ a^{k(p-1)} - 1 }$

is multiple of p.

Let p be a prime divisor of the number N to be factored. If we somehow find a multiple of p-1 we will find a multiple of p which (in general) will not be also a multiple of N, so a greatest common divisor operation will reveal the prime divisor.

Contents

Step 1

Suppose that the largest prime factor of p-1 is less than a bound B1. Then the method proceeds to compute $\displaystyle{ a^E\,\pmod{N} }$ where N is the number to factor.

$\displaystyle{ E = 2^{E_2} * 3^{E_3} * 5^{E_5} * ... * B }$

where $\displaystyle{ E_2 }$ is selected so that $\displaystyle{ 2^{E_2} }$ is about B1 and the same for the other prime numbers. B is the greatest prime number less than or equal to B1.

In general, the number E should be multiple of p-1 because it is multiple of all prime factors of p-1. Notice that when p-1 has a repeated prime factor greater than $\displaystyle{ \sqrt{B1} }$, E will not be multiple of p-1 and the method fails, but this happens with a very low probability.

The Little Fermat Theorem states that $\displaystyle{ a^{p-1}\equiv 1\,\pmod {p} }$. Since E is multiple of p-1 we get $\displaystyle{ a^E\equiv 1\,\pmod {p} }$. This means that $\displaystyle{ a^E-1 }$ will be multiple of p but not of N (in general).

So computing $\displaystyle{ \gcd(a^E-1,\,N) }$ we will get a proper factor of N.

When factoring a number of the form $\displaystyle{ 2^p-1 }$ (as in GIMPS) its prime factors have the form $\displaystyle{ 2kp+1 }$, so the value p must always be a factor of E. In this case the value of a must not be 2, because $\displaystyle{ 2^E\equiv 1\,\pmod {N} }$, so $\displaystyle{ \gcd(2^E - 1, \,N) = N }$, which is a trivial factor of N.

Step 2

Most of the composite numbers have a prime factor much greater than the other prime factors. Suppose that all prime factors of p-1 are less than the bound B1 except for one prime factor which is in the range B1 to B2. In this case step 1 will not succeed and thus it will not reveal a factor of N.

Let $\displaystyle{ F\equiv a^E\,\pmod N }$ be the output of the step 1.

Also precompute the values $\displaystyle{ S\equiv F^2\,\pmod N }$ and $\displaystyle{ H\equiv F^6\,\pmod N }$.

Let C be the previous multiple of 6 to B1.

Then we compute:

$\displaystyle{ Z_1\equiv F^{C+1}\,\pmod N }$
$\displaystyle{ Z_2\equiv F^{C+7}\equiv Z_1 * H\,\pmod N }$
$\displaystyle{ Z_3\equiv F^{C+13}\equiv Z_2 * H\,\pmod N }$
$\displaystyle{ Z_4\equiv F^{C+19}\equiv Z_3 * H\,\pmod N }$
...

and so on until the exponent reaches B2. Since there is a prime factor of p-1 in the range B1 to B2, there is one value computed that must be congruent to 1 (mod p). This does not cover the case that the factor has the form C+5, C+11, C+17, i.e. congruent to 5 modulo 6. In the first case we have:

$\displaystyle{ F^{C+5}\equiv 1\,\pmod p }$

multiplying by $\displaystyle{ F^2 }$ we get

$\displaystyle{ Z_2\equiv F^{C+7}\equiv S\,\pmod p }$

So we compute $\displaystyle{ Z\equiv (Z_1-1)(Z_2-1)(Z_2-S)(Z_3-1)(Z_3-S)(Z_4-1)(Z_4-S)...\pmod N }$ and finally gcd(Z, N) will reveal a proper factor of N.

Example

Suppose we want to find a factor of 229-1 with B1 = 10.

Then E = 23 × 32 × 5 × 7 × 29.

The number 29 was included as indicated on the last paragraph in Step 1.

Let a = 3. So the steps are:

$\displaystyle{ 3^2\equiv 9 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 9^2\equiv 81 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 81^2\equiv 6561 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 6561^3\equiv 35437295 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 35437295^3\equiv 518991192 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 518991192^5\equiv 142236746 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 142236746^7\equiv 237876521 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
$\displaystyle{ 237876521^{29}\equiv 171331425 }$ (mod $\displaystyle{ 2^{29} - 1 }$)
gcd($\displaystyle{ 171331425-1 }$,$\displaystyle{ 2^{29}-1 }$) = $\displaystyle{ 486737 }$.

So 229 - 1 = 486737 × 1103.

Notice that the factor found is composite. This normally occurs when B1 is too high (10 in this case).

For GIMPS, where the exponents are very high, the values of B1 are selected above 1,000,000.