Difference of two squares Created 2026-09-24 Updated 2026-11-05
The difference of two squares identity isIt follows by expanding the right side and cancelling its cross terms. It holds for real numbers and, more generally, in a commutative ring.
For integers , the factors and have the same parity. Conversely, any integer factorization with factors of the same parity yields and . Thus an integer is a difference of two squares exactly when it is not congruent to two modulo four: odd values use , and multiples of four use . This is the factor-pair interpretation behind Fermat's factorization method.
Fermat's factorization method Created 2026-10-14 Updated 2026-11-05
For a positive odd integer , Fermat's factorization method searches for integers satisfying . Start at and test successive values until is a perfect square . The difference of two squares then gives . For an even input, remove factors of two first.
The search always reaches at least the trivial factor pair , at . It is useful when a nontrivial factor pair is close: that pair is reached at , withA small difference between factor sizes therefore requires few trials. This is a different advantage from looking for a small prime factor by trial division.