Density of $d$ for which a generalized Pell equation has a solution 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)$.
 A: (Upgrading comments to answer.)
Counting the number of $D$ for which the equation has a rational solution is a fairly classical problem. This is asymptotic to $c_nD/(\log D)^{1/2}$ for some $c_n > 0$. The case $n=1$ is a result due to Landau and Ramanujan independently:
https://mathworld.wolfram.com/Landau-RamanujanConstant.html
The case of general $n$ follows a similar method and is due to Landau I believe.
This in particular gives the upper number $O(D/(\log D)^{1/2})$ for the number which have an integral solution.
In fact, at least for $n=1$, one expects that a positive proportion of those with a rational solution have an integral solution, so the count for integral solutions is conjecturally asymptotic to some constant times $D/(\log D)^{1/2}$. This conjecture is due Stevenhagen, who also gave a precise formula for the constant, and in fact a correct of magnitude result is a famous theorem of Fouvry and Klüners.
I don't see why the case of general $n$ should be any different, so your expectation of $D^{1/2}$ is almost certainly false.
A: Recently Koymans and Pagano have established an asymptotic formula in this setting: $n$ a prime with $n$ congruent to $3$ modulo $4$, within the family of $d$ where $n$ ramifies in $\mathbb{Q}(\sqrt{d})$ and with $d$ congruent $3$ modulo $4$ (in general they consider the principal quadratic form), see https://arxiv.org/pdf/2005.14157.pdf. They also improve upper and lower bounds of Fouvry and Kluners for $n=1$.
A: 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.
