# Factorising with Gaussian integers

It always struck me as cool, in A-level questions, when you’d see two completely different triangles with the same hypotenuse – for example, a $(4,7,\sqrt{65})$ triangle and a $(1,8,\sqrt{65})$ triangle. But it’s not just cool – it’s also useful.

If you can write a number as the sum of two squares in two non-trivially different ways ($65 = 8^2 + 1^2 = 7^2 + 4^2$), you can find some of that number’s factors.

If it was the *difference* of two squares, you’d be all set – $a^2-b^2 = (a-b)(a+b)$, and there you go, two factors.

It turns out, you *can* write 65 as the difference of two squares ((and I don’t just mean $65 = 33^3 - 32^2$)) if you use *Gaussian integers* – complex numbers with integer coefficients.

For example, $65 = 8^2 - \i^2$, so $65 = (8-\i)(8+\i)$. Similarly, $65 = (7-4\i)(7+4\i)$. But how does that help us?

We’ve got $65^2 = (8-\i)(8+\i)(7+4\i)(7-4\i)$. Let’s split them into different pairs:

\[\begin{align} 65^2 &= [(8-\i)(7+4\i)][(8+\i)(7-4\i)]\\ &= [60 + 25\i][60 - 25\i]\\ &= [5(12+5\i)][5(12-5i)]\\ &= 5^2 \times 13^2\end{align}\]So $65^2 = 5^2 \times 13^2$, and $65 = 5 \times 13$.

This might seem like overkill, especially for a number with an obvious factor - but it’s a neat trick that works with gnarlier composites too. Have fun with it!

* Thanks to Andrew Stacey for a helpful LaTeX suggestion.