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.

  • $\begingroup$ repl.it/repls/FaithfulLazyAustraliankelpie $\endgroup$ Nov 25, 2017 at 19:26
  • 3
    $\begingroup$ @mathnoob123: This one is more efficient, I think. $\endgroup$
    – Kevin
    Nov 25, 2017 at 20:13
  • 5
    $\begingroup$ Is there anything saying that all $x_i$ must be distinct from all $y_i$? $\endgroup$ Nov 25, 2017 at 23:23
  • 2
    $\begingroup$ @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). $\endgroup$ Nov 26, 2017 at 17:35
  • 2
    $\begingroup$ 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. $\endgroup$ Nov 27, 2017 at 5:50

5 Answers 5


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).

  • 1
    $\begingroup$ 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. $\endgroup$
    – Jack M
    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


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$

  • $\begingroup$ Hmm looks elegant. How did you come up with? $\endgroup$
    – ZFR
    Nov 25, 2017 at 20:00
  • $\begingroup$ @RTZ: Updated post $\endgroup$ Nov 25, 2017 at 20:09
  • $\begingroup$ @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$ $\endgroup$
    – PM 2Ring
    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.

  • $\begingroup$ And Dirichlet proved that there are infinitely many such primes. $\endgroup$
    – B. Mehta
    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$$

  • $\begingroup$ 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.) $\endgroup$
    – user325968
    Nov 25, 2017 at 19:26
  • 1
    $\begingroup$ 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. $\endgroup$ Nov 25, 2017 at 19:32
  • $\begingroup$ 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. $\endgroup$
    – user325968
    Nov 25, 2017 at 19:34
  • 1
    $\begingroup$ Anyway, your first comment no longer applies. $\endgroup$ Nov 25, 2017 at 19:46

Not the answer you're looking for? Browse other questions tagged .