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.
 A: 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 $
A: COMMENT.-Theoretically, this problem involves the representation of a rational integer by a binary quadratic form $ax^2+by^2=n$ . In this case for a prime $n=1009$ (when $a=b=1$ one has the well known Fermat's theorem and $x^2+y^2=1009$ has solution because $1009\equiv 1\pmod4$ but, for example, for the prime n = 1019 there is no solution ).
For the other two questions the conditions of solvability are fulfilled too but these ones are something more elaborate.These conditions can be found in the  book Diophantine equations,by J.L. Mordell page 164-166.
When you know that the equations have a solution you can try to find them, as long as the number $n$ is not very large.
A: You can solve this easily using Excel. Clearly $0\leq x\leq \lfloor \sqrt{1009}\rfloor=31$ and
$$
1009=x^2+a y^2 \rightarrow y=\sqrt{1009-x^2\over a}
$$
(here $a=1,2,3$). Just build a table of $y=\sqrt{1009-x^2\over a}$ for the 32 possible values of $x$ and check for integer $y$'s. You get the solutions
$$
1009= 28^2+15^2 = 19^2 + 2\times 18^2 = 31^2 + 3 \times 4^2.
$$

Of course you can also easily program this if you know how to code.
A: $$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$.
