For how many $0 < d \leq D$ is there an integer solution to


$$x^2-dy^2 = -n$$


for $n > 1$? I have circumstantial reason to believe it might be $\sim D^{\frac{1}{2}}$ but I'd be interested in any upper bound that is $o(D)$.



Density of $d$ for which a generalized Pell equation has a solution
To expand on Dan's answer, for general $n \in \mathbb{Z}$ the equation


$$\displaystyle x^2 - dy^2 = n$$


is soluble in integers $x,y$ only if the quadratic form


$$\displaystyle q\_{d,n}(x,y,z) = x^2 - dy^2 - nz^2$$


is everywhere locally soluble, i.e., it is soluble over $\mathbb{R}$ and over $\mathbb{Q}\_p$ for every prime $p$. That it is soluble over $\mathbb{R}$ is clear, since we assumed that $d > 0$ so the ternary quadratic form $q\_{d,n}$ is guaranteed to be indefinite.


Notice that we may assume that $d,n$ are both square-free, since we can absorb any square factors into the variables. For simplicity we shall assume that $\gcd(d,n) = 1$.


It is a well-known theorem of Legendre that for a diagonal ternary quadratic form $q\_{d,n}$ is soluble over all primes $p$ if and only if the congruences


$$\displaystyle \begin{cases} v^2 \equiv n \pmod{d} \\ v^2 \equiv d \pmod{n} \end{cases}$$


are both soluble. The second condition is equivalent to requiring that every prime factor of $d$ splits over (the ring of integers of) the quadratic field $\mathbb{Q}(\sqrt{n})$, and the number of such $d \leq X$ satisfying this condition is $\sim c\_n X(\log X)^{-1/2}$ for some $c\_n > 0$. The first condition is saying that $d \equiv \square \pmod{p}$ for every prime $p | n$ (and also possibly accounting for $-1$ when $n$ is negative), so only introduces a multiplicative factor depending only on $n$. We thus get an upper bound of $O\_n(X(\log X)^{-1/2})$.


In principle the method of Fouvry-Kluners can be used in general to produce a lower bound of the same order of magnitude I believe.


