The difference of two squares identity is
It 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.
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.
For example, starts at . The differences and fail the perfect square test, whereas . Hence .
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 , with
A small difference between factor sizes therefore requires few trials. This is a different advantage from looking for a small prime factor by trial division.

Articles by others on the same topic (1)

The "Difference of Two Squares" is a mathematical concept and a specific algebraic identity that expresses the difference between the squares of two quantities. It is represented by the formula: \[ a^2 - b^2 = (a - b)(a + b) \] In this equation: - \(a\) and \(b\) are any numbers or algebraic expressions. - \(a^2\) is the square of \(a\).