4neurons logo

This one is quite interesting. It was second working algorithm of mine. This algorithm finds 2 factors of n. It works fast if n has 2 factors that are close to each other.

Let n be composite number. We can write it as n=p∙q (if n has more than 2 prime factors then in this equation p or q is not prime (non-exclusive or)).
We can transform that equation to achieve this one:
(p+q)2=(p-q)2+4n
Piragoras Factorize
I tried to use this simple property to limit range of p+q, but boundaries of such limitation still grows exponentially to the number of digits of n.
The idea was as simple as naive. If |p-q| is very small comparing to n then p+q≈2√n.


Code