Solve $x^2+a\, y^2=1009$ for integer $x$ and $y$. The question is :


  Write 1009 in the form $(x^2+a\,y^2)$ for $a=1,2,3$.
  Where $x$ and $y$ are integers.


It is a question where we have to show our work but I know no method other than trial and error which is obviously not allowed... So please tell the correct method/trick to solve the question. Although I found answer for the first part by guess work which is:
$(28)^2 + (15)^2 =1009$.
But as I mentioned above we can not simply write this we have to show the work so please help.
One way is check if there is an element in $\mathbb{Z}[\sqrt D ]$ with $D$ square-free (i.e if the form $a+b\sqrt{D}$) with norm 1009.

That number $z=a+b\sqrt{D}$ must to be prime in $\mathbb{Z}[\sqrt D ]$ because divisibility of its norm.

$15^2+28^2=1009$

$19^2+2\cdot18^2=1009$

$31^2+3\cdot 4^2=1009$

$15^2+4\cdot 14^2=1009 $

$17^2+5\cdot 12^2=1009 $
$$1009 = 15^2+28^2$$

$$1009 = 19^2+2\cdot 18^2$$

$$1009 = 31^2+3\cdot 4^2$$



Well I calulate this values manualy with the use of calculator. Just write $y = \sqrt{1009-x^2}$ for the first case where $x\leq 31 =[\sqrt{1009}]$.



$y = \sqrt{1009-x^2 \over 2}$ for the second case where $x\leq 31$ and odd.



$y = \sqrt{1009-x^2 \over 3}$ for the last case where $x\leq 31$.