# Number which is simultaneously sum of 2 and 3 squares [closed]

Is there positive integer $m$ such $m=x_1^2+x_2^2$ and $m=y_1^2+y_2^2+y_3^2$ where $x_i, y_j$ are nonzero integers. I have tried by hand for the ten natural numbers but I was not able to find such $m$.

Would be thankful for help.

• repl.it/repls/FaithfulLazyAustraliankelpie Nov 25, 2017 at 19:26
• @mathnoob123: This one is more efficient, I think. Nov 25, 2017 at 20:13
• Is there anything saying that all $x_i$ must be distinct from all $y_i$? Nov 25, 2017 at 23:23
• @apnorton The linked answer is not great, the itertools example doesn't construct a tuple in the loop body (this is done behind the scenes) and avoids two list look-ups. Here's a Python 3 example which shows that explicit loops are faster. In practice, it rarely matters either way because the loop body is usually more expensive than the iteration (which was the inspiration for the original comment, but I didn't notice that the first example re-checked combos). Nov 26, 2017 at 17:35
• Pythagorean triples #1: (3,4,5) and #2 (5,12,13) have hypotenuse of the first as a side in the second, so 169 = 144 + 25 = 144 + 16 + 9. Nov 27, 2017 at 5:50

Obviously, if there are any solutions to $a^2 =b^2 + c^2$, then you can add $x^2$ to both sides and get your $m$'s.

For example, $25 + x^2 = 9 + 16 + x^2$ for all natural numbers $x$.

You can even have $m$ be a perfect square AND a sum of two squares AND a sum of three squares (take $x=12$ above).

• The equivalent for Pythagorean triples would be to start with a solution to $a^2=0$ and add $x^2$ to both sides. This does answer the question, but it would be reasonable to require that no integer appears on both sides of the equation. Nov 26, 2017 at 17:37

There is a possibly famous identity: $$\Large 10^2+11^2+12^2=13^2+14^2$$ which meets your criteria.

Here $m$ is $365$.

Alternatively you could use a formula to generate examples; for example

$$m=\left(a^2+b^2+c^2\right)^2+\left(a^2-c^2\right)^2=\left(a^2+c^2\right)^2+\left(2cb\right)^2+\left(a^2+b^2-c^2\right)^2$$

originating from the identity $$\left(a^2+b^2+c^2\right)^2-\left(a^2+b^2-c^2\right)^2=\left(2ca\right)^2+\left(2cb\right)^2$$ and using $$\left(a^2+c^2\right)^2-\left(a^2-c^2\right)^2=\left(2ca\right)^2$$

to substitute for $\left(2ca\right)^2$

• Hmm looks elegant. How did you come up with?
– ZFR
Nov 25, 2017 at 20:00
• @RTZ: Updated post Nov 25, 2017 at 20:09
• @RFZ It's a logical extension of an ancient parametrization for generating Pythagorean triads, $(u^2 - v^2)^2 + (2uv)^2 = (u^2 + v^2)^2$ Nov 26, 2017 at 0:56

Here's a theoretical answer: any prime $p$ of the form $8k+1$ will work (this gives infinitely many examples, including the example of 17 in Dietrich's example).

Why is this true?

First, Fermat proved that any prime $p$ of the form $8k+1$ (in fact 1 mod 4) is of the form $x^2+y^2$. Being prime, it's not a square so both $x, y$ must be nonzero for $x^2+y^2=p$.

Second, Fermat also proved that any prime $p$ of the form $8k+1$ (in fact 1 or 3 mod 8) is of the form $x^2+2y^2$. Again, no prime can be of the form $x^2$ or $2y^2$, so we need both $x,y$ nonzero for $x^2+2y^2=p$. Then $p=x^2+y^2+z^2$ with $z=y$ and $x,y,z$ all nonzero.

• And Dirichlet proved that there are infinitely many such primes. Nov 26, 2017 at 21:44

Combine the sequences A001481 and A000378. The positive integers appearing in both sequences are sum of two squares, and a sum of three squares, e.g., $$17=16+1=4+4+9$$

• The first sequence is for sums of two DISTINCT squares. There was nothing about "distinct" in the question. And the second sequence you linked to is for sums of FOUR squares. (Which is why 17, your example, does not even appear in the second sequence.)
– user325968
Nov 25, 2017 at 19:26
• Corrected. But distinct or not does not matter, because $17$ still is a valid example, and the OP just wanted "a sum" of two squares, resp. three squares. Nov 25, 2017 at 19:32
• Understood; my point was, suppose there were no overlaps between the two lists, that wouldn't answer the original question. You proved existence in even more restrictive conditions that the OP had.
– user325968
Nov 25, 2017 at 19:34
• Anyway, your first comment no longer applies. Nov 25, 2017 at 19:46