In: Advanced Math
Write a procedure that implements the Fermat factorization method done in Mathematica.
Given a number , Fermat's factorization methods look for integers and such that . Then
and
is factored.
Every positive odd integer can be represented in the form by writing (with ) and noting that this gives
Adding and subtracting
so solving for
and
gives
Therefore,
As the first trial for
, try
, where
is the ceiling function. Then check if
is a square number. There are only
combinations of the last two digits which a square number can
assume, so most combinations can be eliminated. If
is not a square number, then try
so
Continue with
so subsequent differences are obtained simply by adding two.
This is the procedure to implement Fermat factorization Method.