Number Theory – What Numbers Can Be Written Uniquely as a Sum of Two Squares?

algebraic-number-theorydiophantine equationselementary-number-theorynumber theory

What numbers can be written uniquely as a sum of two squares?

I was looking at sequence A125022, which shows the numbers that can be uniquely written as a sum of two squares. Here are a few things that I noticed from the first numbers. We have $1$, $2$, $4$, $8$, $16$, $32$, $64$, $128$. It is then safe to assume that all numbers of the form $2^{s}$ can be written uniquely, where $s \in \mathbb{Z}_{+} \cup \{0\}$. Moreover, primes of the form $4k+1$, for example $5$ and $13$, also appear and, interestingly enough, $5^2$ and $13^{2}$ do not. So, we could also say that $p^{s}$ has a unique representation only when $s = 0$ or $s = 1$. If we analyze $A125022$ a bit more, we notice that $3^{2}$, $7^{2}$, $11^{2}$ are there, so we can conjecture that numbers of the form $q^{2}$ have a unique representation, where $q$ is a prime of the form $4k+3$. Furthermore, for reasons I will say later, I believe $d^{2}$, where $d$ has all of its prime factors of the form $4k+3$, can be uniquely represented as a sum of two squares. It is also possible to see that products of these three cases are in the sequence, for example $2^{2}\cdot 5$, $2 \cdot 5 \cdot 3^{2}$ and $2 \cdot 7^{2}$.

Conjecture. A number $n \in \mathbb{Z}_{+}$ can be written uniquely as a sum of two squares if, and only if, $n = 2^{s} d^{2} p^{e_1}$, where $s \in \mathbb{Z}_{+} \cup \{0\}$, $d = 1$ or $d$ has all of its prime divisors of the form $4k+3$, $p$ is a prime of the form $4k+1$ and $e_{1} \in \{0,1\}$.

It is known that a number can be written as a sum of two squares if, and only if, it can be written as $2^{s} t^{2} l$, where $s \in \mathbb{Z}_{+} \cup \{0\}$ and $l$ is a square-free positive integer with all of its prime factors of the form $4k+1$. Thus, we know the number $n$ we conjectured above can in fact be written as a sum of two squares. We only need to understand uniqueness. It is more natural to study these questions with the Gaussian integers, $\mathbb{Z}[i]$. If, for example, we have
$$n = a^{2} + b^{2} = (a+ib)(a-ib) = (\pi_1 \cdots \pi_k) (\overline{\pi_1} \cdots \overline{\pi_k}),$$
where the last expression is the factorization of $n$ in primes of $\mathbb{Z}[i]$, then we may get different sum representations of $n$ by exchanging, say, $\pi_j$ for $\overline{\pi_j}$. That is, the product
$$(\pi_1 \cdots \overline{\pi_j} \cdots \pi_n)(\overline{\pi_1} \cdots \pi_j \cdots \overline{\pi_n})$$
should yield a different sum when $\pi_j \neq \overline{\pi_j}$ and at least one of the other primes, say $\pi_i$, also satisfies $\pi_i \neq \overline{\pi_i}$. This does not seem to occur precisely for the numbers conjectured above, which makes me think those are the only numbers that can be uniquely represented.

Question. Is my guess correct or am I missing other numbers?

Best Answer

Your conjecture is correct.

You are missing no numbers. Any number not on your list would contain a prime power $q^e$ with $q$ of the form $4k+3$, $e$ odd, or a prime power $p^e$ with $p$ of the form $4k+1$ with $e\ge2$, or at least two primes $p_1$, $p_2$ of the form $4k+1$. In the first case $n$ cannot be written as sum of two primes at all, and in the second and third case one obtains readily several different representations of $n$. An essential ingredient to see this is the Brahmagupta-Fibonacci Identity

Each number on your list has actually only one representation. This can be most easily seen by looking at the prime decomposition of $n$ in the ring of Gaussian integers $\mathbb{Z}[i]$, and considering the fact that $\mathbb{Z}[i]$ has unique prime number decomposition up to units. Choosing different units does not result in different representations. Essentially all different representations arise from combining the factors in $\mathbb{Z}[i]$ of the prime decompositions $p_i=(a+bi)(a-bi)$, where $p_i$ is of form $4k+1$, in different ways. For the numbers on your list, there is just one prime $p_i$ of form $4k+1$, hence no different combinations are possible. Your number $d^2$ has only one representation $d^2=d^2+0$, since all prime factors of $d^2$ have form $4k+3$ and therefore are indecomposable ("inert") in $\mathbb{Z}[i]$.

Related Question