Quadratic equation system $A^2 + B^2 = 5$ and $AB = 2$ Given a system of equations

$A^2 + B^2 = 5$
$AB = 2$

what is the correct way to solve it?
I see immediately that the answers are

*

*$A=1, B=2$

*$A=2, B=1$

*$A=-1, B=-2$

*$A=-2, B=-1$
but I don't understand the correct way of getting there. I have tried to isolate one of the variables and put the resulting expression into one of the equations, but this didn't get me anywhere. What is the correct way of solving this problem?

If
$a^2+b^2 = c$
and
$ab = d$
then
$(a+b)^2
=a^2+2ab+b^2
= c+2d
$
and
$(a-b)^2
=a^2-2ab+b^2
= c-2d
$.
Therefore
$a+b = \sqrt{c+2d}$
and
$a-b = \sqrt{c-2d}$
so
$a = \frac12(\sqrt{c+2d}+\sqrt{c-2d})
$
and
$b = \frac12(\sqrt{c+2d}-\sqrt{c-2d})
$.
If $c=5, d=2$,
then
$\sqrt{c+2d} = 3$
and
$\sqrt{c-2d} = 1$
so
$a= 2$
and
$b = 1$. 
If you want to get
all the solutions,
you can write
$a = \frac12(\pm\sqrt{c+2d}\pm\sqrt{c-2d})
$
and
$b = \frac12(\pm\sqrt{c+2d}\mp\sqrt{c-2d})
$
for all possible signs.
