Solve $$x^2-py^2=q$$ for integers $x,y$, here $p,q$ are both given prime numbers.
It's obvious that $p,q$ should satisfy $(\frac{p}{q})=(\frac{q}{p})=1,$ here $(\frac{p}{q})$ is the Jacobi symbol. However,this is not sufficient,for example,$(\frac{11}{37})=(\frac{37}{11})=1$,but $x^2-37y^2=11$ has no integer solution.
Addition:Maybe it's too hard to analysis this problem in general,one can analysis it in case of $p=37$.What's the necessary and sufficient condition so that $x^2-37y^2=q$ has integer solutions?It's known that the class number of $Q(\sqrt{37})$ is $1$.
This kind of question is answered by looking at how $q$ factors in a precise abelian extension of $\Bbb Q(\sqrt p)$.
In your example, $\Bbb Q(\sqrt p)$ has class number $1$. Its ring of integer is $\Bbb Z\left[\frac{1+\sqrt {37}}2\right]$, and the norm quadratic form is $x^2+xy-9y^2$. $11$ splits in this quadratic extension, so it is a norm, as $11 = 4^2+4-9$.
Now, your quadratic form has discriminant $4*37$. It is the norm form of the lattice $\Bbb Z[\sqrt{37}]$, so the question is : When do the primes that split, give primes that land on this lattice (up to multiplication by a unit) ?
A quick computation shows that the units are generated by $6 \pm \sqrt {37}$, and importantly, they are in $\Bbb Z[\sqrt{37}]$, and $(6+\sqrt{37})(6- \sqrt{37}) = -1$. Hence, modulo $(2)$ and the two infinite places, the units are $\{\overline 1 \}\times\{\pm 1\}^2$. This also shows that $-1$ is represented by $x^2+xy-9y^2$ and $x^2-37y^2$, and that the positive represented primes are the same are the negative represented primes.
The elements of $\Bbb Z[\sqrt {37}]$ are those congruent to $0,1$ modulo the ideal $(2)$. Those who are prime are then (except $2$) those congruent to $1$ modulo $(2)$, and so we are looking for the primes which are in the trivial class of $G = \left(\Bbb Z\left[\frac{1+\sqrt {37}}2\right]/(2)\right)^* \approx \Bbb Z/3 \Bbb Z$, and which is the ray class group of conductor $(2)\infty_1\infty_2$ (quotienting by the units removes the sign components of the infinite places).
Now, as a reality check, the primes of norm $11$ are $\frac{9 \pm \sqrt{37}}2 \equiv \frac{1 \pm \sqrt{37}}2 \neq 1 \pmod {(2)}$
According to class field theory, the primes that land in the trivial class (and so are representable as $x^2-37y^2$) are those that split in a particular abelian cubic extension $K$ of $\Bbb Q(\sqrt {37})$. If by chance $K$ is abelian over $\Bbb Q$, then we know from Kronecker's theorem that this is equivalent to a modular condition on the original prime, and it should be obvious when looking back at $x^2-37y^2$ mod $4*37$.
Sadly this is not the case : $x^2-37y^2$ can take every odd value modulo $4$, and so the Galois group of $K$ over $\Bbb Q$ is not abelian, but it is $S_3$. So there should be a cubic polynomial $P(X) = X^3+aX+b$, such that $x^2-37y^2$ represents a prime $q$ if and only if $P$ splits into linear factors modulo $q$.
If $P(X) = X^3-4X-2$, it turns out that the class field is the splitting field of $P$, and for $p \neq 37$, we have the equivalences :