Is this factoring method an algorithm?

116 Views Asked by At

$x-y=d$ and $xy=p\,$ gives $x^2-dx-p=0$, with the positive solution $x=\frac{1}{2}\big(d+\sqrt{d^2+4p} \big)$. Consider $x,y,d,p\,$ as integers $>\!0$, where only $p$ is known, in order to factorize $p$. Starting with $d=\!0$ stepping up with $1$ until $d^2+4p$ is a perfect square. Would this value of $d$ guaranty that $x|p$?

While testing hundreds of times I have found no exceptions.


It's not a great method, but with optimal coding it's okay for $x-y<100,000$.

1

There are 1 best solutions below

0
On

As already stated in some comments, this method will work and as Barry Cipra mentioned this is related to Fermat's factoring method. It was first published in 1792 by C.F.Kausler. This and other historical facts I mention in this post can be found in Leonard Dickson's book "History of the Theory of Numbers" in chapter 14, "Methods of Factoring", page 357.

Fermat used that fact that a number that can be split in two factors can be represented as the difference of two squares. If $$n=pq$$ then $$n=a^2-b^2$$ if we select $a,b$ such that

$$q=a-b\\p=a+b$$ we then have $$a=\frac{p+q}2 \\ b=\frac{p-q}2$$

So we have $$a^2-n=b^2$$ and Fermat proposed to check the numbers $a$ where $$a \ge \lceil \sqrt n \rceil$$ until we have found one such that $a^2-n$ is a perfect square. So we have to check the integer numbers in the interval $[\sqrt{pq}, \frac{p+q}2].$

We also can write $$b^2+n=a^2$$ and Kausler and you propose to check all $b\ge0$ until we have found onw such that $b^2-n$ is a perfect square. Her the integer numbers in the interval $[0, \frac{p-q}/2]$ have to be checked. We have $$(p+q)/2-\sqrt{p q}=1/2(\sqrt p -\sqrt q)^2$$ and $$p-q=(\sqrt p -\sqrt q)(\sqrt p+\sqrt q)$$ and so $$\frac{p-q}{(p+q)/2-\sqrt{p q}}=2\frac{\sqrt p+\sqrt q}{\sqrt p-\sqrt q} \tag 1$$ So the numbers to check is for your algorithm higher by the factor $(1)$ than the number of numbers that Fermat's algorithm has to check. In a letter from about 1643 Fermat demonstrated his method bei factoring the number $2027651281=44021\cdot 46061$. Using his method one has to check $11$ numbers, using your method onw has to check $1020$. One can decrease the number that one has actually to check if one considers the residues of squares with respect to a modulus. For example Fermats number has the remainder $81$ modulo $100$.

$$81+b^2\pmod{100}$$ cannot be a square for $b^2\equiv 1\pmod {100}$ or $b^2\equiv 6\pmod {100}$.