Fermat's factorization method

Fermat's factorization method, named after Pierre de Fermat, is based on the representation of an odd integer as the difference of two squares:

That difference is algebraically factorable as ; if neither factor equals one, it is a proper factorization of N.

Every odd number can be represented as such. If is a factorization of N, then: .

Since N is odd, both c and d are also odd, and hence the two terms in parentheses are integers.

In its simplest form, Fermat's method can be even slower than trial division (in the worst case). Nonetheless, combining Fermat's method and trial division can be more efficient than either method alone.