# Find three numbers such that the sum of all three is a square and the sum of any two is a square

It seems like it should be a well known problem. Ive read that Diophantine himself first posed it. I couldnt find a solution when i researched for one.
It asks to find ordered triples $(x,y,z)$ such that $$x+y+z=a^2$$ $$x+y=b^2$$ $$x+z=c^2$$ $$y+z=d^2$$

As an example (41, 80, 320). Any guidance is appreciated. The ideal would be some kind of parametric solution for x, y, and z

• Does a Euler brick exist?? – Bumblebee Aug 5 '17 at 21:23
• @Nil: that is not accurate: here we do not need that $x,y,z$ are squares. – Jack D'Aurizio Aug 5 '17 at 21:26
• @JackD'Aurizio: I just wanted to mention something related. Some times it is helpful to solve problems by looking at similar problems. – Bumblebee Aug 5 '17 at 21:28
• @Nil. That's a cool reference. Nonetheless I'm having trouble seeing how this helps. – AmateurMathPirate Aug 5 '17 at 21:31
• @AmateurMathGuy it's a subset for the last three equations involving squares is one way. based on the equations alone you get,x,y and z must all be a difference of squares. – user451844 Aug 5 '17 at 21:35

## 4 Answers

I did the complete solution for multiplier 3 here: http://math.stackexchange.com/questions/1964607/when-will-a-parametric-solution-generate-all-possible-solutions/1965805#1965805

Back to 2:

With Jack's variables, let $p+q+r+s$ be odd and $\gcd(p,q,r,s) = 1,$ then define $$a = p^2 + q^2 + r^2 + s^2,$$ $$u = 2(-pr + qr +ps+qs),$$ $$v = p^2 - q^2 + r^2 - s^2 + 2 pq + 2rs,$$ $$w = p^2 - q^2 - r^2 + s^2 - 2 pq + 2rs.$$ This gives $$u^2 + v^2 + w^2 = 2 a^2$$ and should give all primitive solutions. Checking, and then proving, that these are all, takes longer than finding the formula.

Notice that $u \equiv 0 \pmod 4,$ because $$-pr + qr +ps+qs \equiv pr + qr +ps+qs \equiv (p+q)(r+s) \pmod 2.$$ As we demanded that $p+q+r+s$ be odd, it is not possible to have both $p+q$ and $r+s$ odd. One of $p+q$ and $r+s$ is odd, while the other is even, meaning the product is even.

=================================

? a = p^2 + q^2 + r^2 + s^2
%1 = p^2 + (q^2 + (r^2 + s^2))
?
?
? u = 2 * ( -p * r + q * r + p * s + q * s    )
%2 = (-2*r + 2*s)*p + (2*r + 2*s)*q
?
? v = p^2 - q^2 + r^2 - s^2 + 2 * p * q + 2 * r * s
%3 = p^2 + 2*q*p + (-q^2 + (r^2 + 2*s*r - s^2))
?
? w = p^2 - q^2 - r^2 + s^2 - 2 * p * q + 2 * r * s
%4 = p^2 - 2*q*p + (-q^2 + (-r^2 + 2*s*r + s^2))
?
?
?
?
? u^2 + v^2 + w^2 - 2 * a^2
%5 = 0
?
?


===========================

Raw search 2 a^2 = u^2 + v^2 + w^2, with odd a,v,w, even u, and v >= w.

  1       0   1   1
3       4   1   1
5       0   7   1
5       4   5   3
7       4   9   1
7       8   5   3
9       4  11   5
9       8   7   7
11       4  15   1
11       8  13   3
11      12   7   7
13       0  17   7
13       8  15   7
13      12  13   5
13      16   9   1
15       8  19   5
15      16  13   5
15      20   7   1
17       0  23   7
17       4  21  11
17       8  17  15
17      20  13   3
17      24   1   1
19       4  25   9
19      12  17  17
19      12  23   7
19      16  21   5
19      24  11   5
21       4  29   5
21       8  23  17
21      16  25   1
21      20  19  11
23       4  31   9
23      12  25  17
23      16  21  19
23      24  19  11
23      28  15   7
23      32   5   3
25       0  31  17
25       4  35   3
25       8  31  15
25      20  27  11
25      20  29   3
25      24  25   7
25      28  21   5
25      32  15   1
27       8  35  13
27       8  37   5
27      16  29  19
27      20  23  23
27      28  25   7
29       0  41   1
29       4  35  21
29       8  33  23
29      12  37  13
29      20  29  21
29      28  27  13
29      36  19   5
29      40   9   1


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    a       u    v    w      p  q  r  s
1       0    1    1      1  0  0  0
3       4    1    1      0  1  1  1
5       0    7    1      0  0  2  1
5       0    7    1      0  0 -2 -1
5       4    5    3      2  0 -1  0
7       4    9    1      2  1  1  1
7       8    5    3      1 -1 -2 -1
9       4   11    5      2  0 -2 -1
9       8    7    7      0  1  2  2
11      12    7    7      3  0 -1  1
11       4   15    1      3  1 -1  0
11       8   13    3      3  1  0  1
13       0   17    7      0  0  3  2
13       0   17    7      0  0 -3 -2
13      12   13    5      3  0 -2  0
13      16    9    1      1  2  2  2
13       8   15    7      2  1  2  2
15      16   13    5      2 -1 -3 -1
15      20    7    1      3  1 -1  2
15       8   19    5      1  1  3  2
17       0   23    7      4  1  0  0
17      20   13    3      0  2  3  2
17      24    1    1      3  0 -2  2
17       4   21   11      2  0 -3 -2
17       8   17   15      4  0 -1  0
19      12   17   17      0  1  3  3
19      12   23    7      3  0 -3 -1
19      16   21    5      4  1 -1  1
19      24   11    5      3 -1 -3  0
19       4   25    9      4  1  1  1
21      16   25    1      3  2  2  2
21      20   19   11      4  1  0  2
21       4   29    5      1  0 -4 -2
21       8   23   17      4  0 -2 -1
23      12   25   17      2  1  3  3
23      16   21   19      3  1  2  3
23      24   19   11      1  2  3  3
23      28   15    7      3  2  1  3
23      32    5    3      1  3  2  3
23       4   31    9      3  1  3  2
25       0   31   17      0  0  4  3
25       0   31   17      0  0 -4 -3
25      20   27   11      2 -1 -4 -2
25      20   29    3      4  2  1  2
25      24   25    7      4  0 -3  0
25      28   21    5      1 -2 -4 -2
25      32   15    1      2 -2 -4 -1
25       4   35    3      2  1  4  2
25       8   31   15      4  1  2  2
27      16   29   19      1 -1 -4 -3
27      20   23   23      5  0 -1  1
27      28   25    7      3 -1 -4 -1
27       8   35   13      5  1 -1  0
27       8   37    5      4  1 -3 -1
29       0   41    1      5  2  0  0
29      12   37   13      3  0 -4 -2
29      20   29   21      5  0 -2  0
29      28   27   13      0  2  4  3
29      36   19    5      4  2  0  3
29      40    9    1      3 -2 -4  0
29       4   35   21      2  0 -4 -3
29       8   33   23      4  0 -3 -2
a       u    v    w      p  q  r  s


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Assume that $$2a^2 = u^2+v^2+w^2$$ holds for some $(a,u,v,w)\in\mathbb{N}^4$ and the system $$\left\{\begin{array}{rcl}y+z&=& u^2 \\ x+z&=&v^2 \\ x+y&=&w^2\end{array}\right.$$ has integer solutions. Then we are done, since $x+y+z=a^2$.
If $u,v,w$ are even numbers the system clearly has integer solutions ($x=\frac{v^2+w^2-u^2}{2}$ and so on), so every triple $(\alpha,\beta,\gamma)\in\mathbb{N}^3$ such that $2(\alpha^2+\beta^2+\gamma^2)$ is a square leads to a solution of the original problem. But, wait. If $2(\alpha^2+\beta^2+\gamma^2)$ is a square it is an even square, i.e. a number of the form $4n^2$. In particular we get a solution of the original problem for every solution of the Diophantine equation $\alpha^2+\beta^2+\gamma^2 = 2n^2$.

For instance, $(\alpha,\beta,\gamma,n)=(0,1,7,5)$ leads to $2(10)^2 = 0^2+2^2+14^2$ and to the solution $$(x,y,z) = (-96,96,100).$$

The solution found by the OP, $(x,y,z)=(41,80,320)$, is associated with $11^2+19^2+20^2=2\cdot 21^2$. Another solution is $(x,y,z)=(-111,120,280)$, which is associated with $3^2+13^2+20^2=2\cdot 17^2$.

• Also I generally do not know how to solve, diophantically, the equation $$2a^2=b^2+c^2+d^2$$. Any references or guidance on that? – AmateurMathPirate Aug 5 '17 at 21:55
• @AmateurMathGuy: such solutions are associated with decompositions $2n^2=a^2+b^2+c^2$ where $a,b,c$ have roughly the same magnitude. For instance, $$(x,y,z)=(57,112,672)$$ is associated with $13^2+27^2+28^2=2\cdot 29^2$. – Jack D'Aurizio Aug 5 '17 at 21:57
• And by Legendre's theorem (en.wikipedia.org/wiki/Legendre%27s_three-square_theorem), any number that is not of the form $4^k(8m+7)$ can be represented as the sum of three squares, so there are plenty of solutions. – Jack D'Aurizio Aug 5 '17 at 21:58
• Outstanding. Your answer has shown me where I need to study. Thank you. – AmateurMathPirate Aug 5 '17 at 22:02
• Jack, all primitive solutions of $a^2 + b^2 + c^2 = 2 d^2$ can be parametrized by $\bar{q} v q,$ where $v$ is a quaternion with real part zero and norm 2, such as $v = i+j;$ meanwhile, $d$ is the norm of $q.$ Here is multiplier 3: math.stackexchange.com/questions/1964607/… – Will Jagy Aug 6 '17 at 0:26

A family of solutions can be obtained from \begin{eqnarray*} x&=&48m^2+8m+1 \\ y&=&96m^2+16m \\ z&=&16m(6m+1)(6m^2+m-1) \end{eqnarray*} One can easily verify that \begin{eqnarray*} x+y&=&(12m+1)^2 \\ x+z&=&(24m^2+4m-1)^2 \\ y+z&=&(4m(6m+1))^2 \\ x+y+z&=&(24m^2+4m+1)^2. \end{eqnarray*}

For the General case of formula there. https://artofproblemsolving.com/community/c3046h1172008_combinations_of_numbers_in_squares

The system of equations:

\left\{\begin{aligned}&a+b=x^2\\&a+c=y^2\\&b+c=z^2\\&a+b+c=q^2\end{aligned}\right.

Solutions have the form:

$$a=4t((2t-p)k^2+2(2t-p)^2k-2p^3+9tp^2-14pt^2+8t^3)$$

$$b=4(p^2-3pt+2t^2)k^2+8(4t^3-8pt^2+5tp^2-p^3)k+$$

$$+4(p^4-6tp^3+15p^2t^2-18pt^3+8t^4)$$

$$c=k^4+4(2t-p)k^3+4(p^2-3pt+3t^2)k^2-8(p^2-3pt+2t^2)tk+$$

$$+4t(2p^3-9tp^2+14pt^2-7t^3)$$

$$x=2(2t-p)(k+2t-p)$$

$$y=k^2+2(2t-p)k+2t^2$$

$$z=k^2+2(2t-p)k+2(t-p)^2$$

$$q=k^2+2(2t-p)k+6t^2-6tp+2p^2$$

$k,t,p$ - integers asked us.