Here is the sort of thing that is not immediately visible in the quadratic field viewpoint. Suppose we have target $n,$ say $\gcd(n,4d) = 1$ and suppose we are able to solve
$$ u^2 \equiv 4 d \pmod {4n}, $$
$$ u^2 = 4d + 4 n t. $$ Then
$$ u^2 - 4 n t = 4 d. $$ Thus we have constructed a quadratic form
$$ \langle n,u,t \rangle $$
of discriminant $4d.$ I meant to guarantee that the form was primitive. By the reduction scheme of Gauss and Lagrange, this form reduces over $SL_2 \mathbb Z$ to some "reduced" form $ \langle a,b,c \rangle $ of the same discriminant, where reduced is equivalent to $ac <0, b > |a+c|.$ This need not be the principal form, and if $n$ is prime there is just one possible form and its "opposite" that represent $n.$
Here is a good one: we can represent $x^2 - 229 y^2 = p$ (for $p \neq 2,3, 229$) if and only if $z^3 - 4 z - 1 $ factors into three distinct factors $\pmod p.$ This is from an Henri Cohen book, appendix. The form class group, reduced, are
916 factored 2^2 * 229
1. 1 30 -4 cycle length 10
2. 3 28 -11 cycle length 18
3. 11 28 -3 cycle length 18
form class number is 3
=====================================================================
Small positive primes x^2 - 229 y^2 :
37 53 173 193 229 241 347 359 383 439
443 449 461 503 509 541 593 607 617 619
643 691 907 967 977
parisize = 4000000, primelimit = 500509
? factormod( z^3 - 4 * z - 1, 37)
%1 =
[Mod(1, 37)*z + Mod(8, 37) 1]
[Mod(1, 37)*z + Mod(13, 37) 1]
[Mod(1, 37)*z + Mod(16, 37) 1]
? factormod( z^3 - 4 * z - 1, 53)
%2 =
[Mod(1, 53)*z + Mod(5, 53) 1]
[Mod(1, 53)*z + Mod(19, 53) 1]
[Mod(1, 53)*z + Mod(29, 53) 1]
? factormod( z^3 - 4 * z - 1, 173)
%3 =
[Mod(1, 173)*z + Mod(26, 173) 1]
[Mod(1, 173)*z + Mod(156, 173) 1]
[Mod(1, 173)*z + Mod(164, 173) 1]
?
============================================
Monday, 19 Feb.: now i remember why I stuck with positive binary forms for my inhomogeneous examples; I just ran $$3 x^2 + 13 x y - 5 y^2 + z^3 - 4 z \neq \pm 1$$ which is very nice. However, in order to have the discriminant of $z^3 - 4 z + r$ to be a square multiple of that for $r=1,$ we get $27 r^2 + 229 w^2 = 256,$ so we get no more. Compare https://mathoverflow.net/questions/12486/integers-not-represented-by-2-x2-x-y-3-y2-z3-z and Kevin Buzzard's answer. The collection of related material, as pdfs, is now at ZAKUSKI INHOM
Probably enough. I like Buell, Binary Quadratic Forms. Similar in Dickson, Introduction to the Theory of Numbers (1929). Comparison of definitions of "reduced" is in Franz Lemmermeyer's 2010 book, page 37 (pdf 43) Theorem 1.36.
For actually finding all representations of some $n$ of intermediate size by an indefinite form, i like Conway's topograph method. It displays both the action of the (oriented) automorphism group of the form and the finite set of representations that are distinct under the group action. Here is one with pretty good illustrations, I found that drawing by hand on paper works best by drawing the "river" on one page (if it will fit) but then draw "trees" leaving the riverside to show the targets http://math.stackexchange.com/questions/739752/how-to-solve-binary-form-ax2bxycy2-m-for-integer-and-rational-x-y/739765#739765
http://www.maths.ed.ac.uk/~aar/papers/conwaysens.pdf and
https://www.math.cornell.edu/~hatcher/TN/TNbook.pdf and
http://www.springer.com/us/book/9780387955872
http://bookstore.ams.org/mbk-105/
The point is to first find a single solution to $x^2-15y^2=61$. Then every other solution is obtained by multiplying by units. I won't prove this here.
First, solving $l^2\equiv15\pmod{61}$ yields the identity
$$25^2=15+61\cdot10\qquad\text{ so }\qquad \frac{(25+\sqrt{15})(25-\sqrt{15})}{10}=61.$$
Now suppose we have integers $z,w\in\Bbb{Z}$ such that $z^2-15w^2=10$. Then $x,y\in\Bbb{Z}$ defined by
$$x+y\sqrt{15}:=(25\pm\sqrt{15})(z\pm w\sqrt{15}),$$
will satisfy $x^2-15y^2=61$. So we've reduced the problem to finding a solution to $z^2-15w^2=10$.
By the exact same method, solving $k^2\equiv15\pmod{10}$ yields the identity
$$5^2=15+10\qquad\text{ so }\qquad(5+\sqrt{15})(5-\sqrt{15})=10.$$
Putting these together shows that
$$61=\frac{(25+\sqrt{15})(25-\sqrt{15})}{(5+\sqrt{15})(5-\sqrt{15})}
=\frac{1}{10^2}(5+\sqrt{15})(5-\sqrt{15})(25+\sqrt{15})(25-\sqrt{15}).$$
So all $x,y\in\Bbb{Z}$ with $x^2-15y^2=61$ are of the form
$$x+y\sqrt{15}=u\cdot\frac{1}{10}(5\mp\sqrt{15})(25\pm\sqrt{15}),$$
where $u\in\Bbb{Z}[\sqrt{15}]^{\times}$ is any unit.
For values other than $61$ the process might be longer or shorter; here we were reduce to the classical Pell equation in two steps, consecutively solving the diophantine equations
$$x^2-15y^2=61,\qquad x^2-15y^2=10,\qquad x^2-15y^2=1.$$
What can be said is that the right hand side decreases with every step, so this process does eventually terminate.
Best Answer
As Batominovski indicated in comments, if you know a solution $(x,y)$ to $x^2-dy^2=1$,
then $(X,Y)=(2x,2y)$ is a solution to $X^2-dY^2=4$,
because $X^2-dY^2=(2x)^2-d(2y)^2=4x^2-d4y^2=4(x^2-dy^2)=4(1)=4.$
For example, solutions to $x^2-5y^2=1$ are $(x,y)=(1,0), (9,4), (161,72), ...$,
so solutions to $X^2-5Y^2=4$ are $(X,Y)=(2,0), (18,8), (322, 144), ...$.
So this shows that $X^2-5Y^2=4$ has solutions, though there are solutions this does not find,
such as $(X,Y)=(3,1),(7,3),(47,21),(123,55),(843,377), ...$.