Fermat's factorization method is an integer factorization algorithm that relies on the representation of an odd integer as the difference of two squares. It's particularly effective for numbers that are the product of two factors that are close to each other.
Given an odd integer
Where:
-
and are integers. -
is slightly larger than the square root of . -
is found iteratively.
The factorization then gives us:
-
Initialization:
- Compute
as the ceiling of , i.e., . - Set
.
- Compute
-
Iteration:
- While
is not a perfect square: - Increment
by 1. - Recompute
.
- Increment
- While
-
Factorization:
- Once
is a perfect square, compute . - The factors of
are and .
- Once
Let's factorize
-
Initialization:
-
. -
, which is not a perfect square.
-
-
Iteration:
- Increment
to 79. -
, which is still not a perfect square. - Increment
to 80. -
, which is a perfect square.
- Increment
-
Factorization:
-
. - The factors of 5959 are
and .
-
Thus,
The main program implementing Fermat's factorization method takes an odd integer
-
Input: An odd integer
. -
Output: The factor
, where .
For instance, given the input
Fermat's factorization method is most efficient when the factors of
- Wikipedia: Fermat's factorization method
- Números Inteiros e Criptografia RSA.
- Other books and research papers on integer factorization and number theory.