Let $f(x,y) = ax^2 + 2bxy + cy^2$ be a binary quadratic form. The discriminant of this is $D = -b^2 + ac$.
Let $N$ be a positive integer. I would like to construct a binary quadratic form $f(x,y)$ that represents $N$ with the constraint that $-\lfloor {\sqrt{N}}\rfloor < D < \lfloor {\sqrt{N}}\rfloor$.
What I have tried so far: Fix $y = 1$ to get $f(x,1) = ax^2 + 2bx + c$. Now, for $x \ge 2 \in \mathbb Z$, get a base-$x$ representation of $N$, but stop after the second division and collect the quotient and remainders. Verify the coefficient of $x$ in the base-$x$ representation is even (i.e., must be $2b$) and then check $-\lfloor {\sqrt{N}}\rfloor < D < \lfloor {\sqrt{N}}\rfloor$. If conditions not met, try the next $x$. While the procedure produces $(a,b,c)$ that yields a binary quadratic form that represents $N$, it doesn't necessarily meet the $-\lfloor {\sqrt{N}}\rfloor < D < \lfloor {\sqrt{N}}\rfloor$ constraint.
The other approach I have tried is quite similar. Fix $c$. We then have $N - c = ax^2 + 2bx = x(ax+2b)$. Therefore, $x|(N-c)$. This approach is suitable to narrow down the $x$ to just the divisors of $N - c$, but unsuitable when $N$ gets large (due to the need for factoring).
How does one go about achieving this, keeping in mind that $N$ is large?