In
number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
, Dixon's factorization method (also Dixon's random squares method
or Dixon's algorithm) is a general-purpose
integer factorization
In mathematics, integer factorization is the decomposition of a positive integer into a product of integers. Every positive integer greater than 1 is either the product of two or more integer factors greater than 1, in which case it is a comp ...
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
; it is the prototypical
factor base method. Unlike for other factor base methods, its run-time bound comes with a rigorous proof that does not rely on conjectures about the smoothness properties of the values taken by a polynomial.
The algorithm was designed by
John D. Dixon, a mathematician at
Carleton University
Carleton University is an English-language public university, public research university in Ottawa, Ontario, Canada. Founded in 1942 as Carleton College, the institution originally operated as a private, non-denominational evening college to se ...
, and was published in 1981.
Basic idea
Dixon's method is based on finding a
congruence of squares modulo the integer N which is intended to factor.
Fermat's factorization method finds such a congruence by selecting random or
pseudo-random
A pseudorandom sequence of numbers is one that appears to be statistically random, despite having been produced by a completely deterministic and repeatable process. Pseudorandom number generators are often used in computer programming, as tradi ...
''x'' values and hoping that the integer ''x''
2 mod N is a
perfect square (in the integers):
:
For example, if , (by starting at 292, the first number greater than and counting up) the is 256, the square of 16. So . Computing the
greatest common divisor
In mathematics, the greatest common divisor (GCD), also known as greatest common factor (GCF), of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers , , the greatest co ...
of and ''N'' using
Euclid's algorithm gives 163, which is a factor of ''N''.
In practice, selecting random ''x'' values will take an impractically long time to find a congruence of squares, since there are only squares less than ''N''.
Dixon's method replaces the condition "is the square of an integer" with the much weaker one "has only small prime factors"; for example, there are 292 squares smaller than 84923; 662 numbers smaller than 84923 whose prime factors are only 2,3,5 or 7; and 4767 whose prime factors are all less than 30. (Such numbers are called ''
B-smooth'' with respect to some bound ''B''.)
If there are many numbers
whose squares can be factorized as
for a fixed set
of small primes, linear algebra modulo 2 on the matrix
will give a subset of the
whose squares combine to a product of small primes to an even power — that is, a subset of the
whose squares multiply to the square of a (hopefully different) number mod N.
Method
Suppose the composite number ''N'' is being factored. Bound ''B'' is chosen, and the ''
factor base'' is identified (which is called ''P''), the set of all primes less than or equal to ''B''. Next, positive integers ''z'' are sought such that ''z''
2 mod ''N'' is ''B''-smooth. Therefore we can write, for suitable exponents ''a
i'',
:
When enough of these relations have been generated (it is generally sufficient that the number of relations be a few more than the size of ''P''), the methods of
linear algebra
Linear algebra is the branch of mathematics concerning linear equations such as
:a_1x_1+\cdots +a_nx_n=b,
linear maps such as
:(x_1, \ldots, x_n) \mapsto a_1x_1+\cdots +a_nx_n,
and their representations in vector spaces and through matrix (mathemat ...
, such as
Gaussian elimination
In mathematics, Gaussian elimination, also known as row reduction, is an algorithm for solving systems of linear equations. It consists of a sequence of row-wise operations performed on the corresponding matrix of coefficients. This method can a ...
, can be used to multiply together these various relations in such a way that the exponents of the primes on the right-hand side are all even:
:
This yields a
congruence of squares of the form which can be turned into a factorization of ''N'', This factorization might turn out to be trivial (i.e. ), which can only happen if in which case another try must be made with a different combination of relations; but if a nontrivial pair of factors of ''N'' is reached, the algorithm terminates.
Pseudocode
This section is taken directly from Dixon (1981).
Dixon's algorithm
''Initialization.'' Let ''L'' be a list of integers in the range
, ''n'' and let ''P'' = be the list of the ''h'' primes ≤ ''v''. Let ''B'' and ''Z'' be initially empty lists (''Z'' will be indexed by ''B'').
Step 1. If ''L'' is empty, exit (algorithm unsuccessful). Otherwise, take the first term ''z'' from ''L'', remove it from ''L'', and proceed to Step 2.
Step 2. Compute ''w'' as the least positive remainder of ''z
2 mod n''. Factor ''w'' as:
where ' has no factor in ''P''. If ' = 1, proceed to Step 3; otherwise, return to Step 1.
Step 3. Let ''a'' ← (''a''
1, ..., ''a''
h). Add ''a'' to ''B'' and ''z'' to ''Z''. If ''B'' has at most ''h'' elements, return to Step 1; otherwise, proceed to Step 4.
Step 4. Find the first vector ''c'' in ''B'' that is linearly dependent (mod 2) on earlier vectors in ''B''. Remove ''c'' from ''B'' and
from ''Z''. Compute coefficients
such that:
Define:
Proceed to Step 5.
Step 5. Compute:
so that:
If
or
, return to Step 1. Otherwise, return:
which provides a nontrivial factor of ''n'', and terminate successfully.
Step-by-step example : factorizing (''n'' = 84923) using Dixon's algorithm
This example is lifted directly from the LeetArxiv substack.
[Kibicho, Murage (2025)]
''Hand-Written Paper Implementation''
Asymptotically Fast Factorization of Integers. Credit is given to the original author.
* Initialization:
** Define a list of numbers ''L'', ranging from 1 to 84923:
:::
:* Define a value ''v'', which is the smoothness factor:
:::
:* Define a list ''P'' containing all the prime numbers less than or equal to ''v'':
:::
:* Define ''B'' and ''Z'', two empty lists. ''B'' is a list of powers, while ''Z'' is a list of accepted integers:
:::