Finding the Upper and Lower Bounds of Possible $x$ values Given that $n$ is an odd semiprime (not a square of primes), $a=\operatorname{ceil}(\sqrt{n})$ and $b=a^2-n$. We also have a function, $f(x)$, such that $$f(x)=\frac{b-x^2}{2x-2a}$$ For each $n$, there is one trivial $x$ value that is equal to $$x=a-1$$ For each $n$, there is also one non-trivial positive $x$ value that is an integer (not including $0$) that also makes $f(k)$ a positive integer (including $0$). We'll call this $k$. What I am asking is this: what are the tightest bounds that this integer $k$ must be within? The ones I have is: $$-1+\sqrt{1+b+2a}\leq k\leq a-2$$ I don't know if those are the tightest. Also, what I want to know is what are the bounds that $f(k)$ must be within? All bounds must be in terms of $a,b$ and $n$.
 A: The initial premise is wrong. In fact, there are precisely eight integers $k$ such that $f(k)$ is an integer (including $a-1$).
For this $k$ we have $2(k-a)\mid b-k^2$. But we have $b-k^2\equiv b-a^2=-n\pmod{k-a}$, therefore $k-a\mid n$. If we write $n=pq$ with $p,q$ odd primes, then we have $k-a=\pm 1,\pm p,\pm q,\pm pq$. And, indeed, any of those values can appear.
Let $k$ be any of the numbers $a\pm 1,a\pm p,a\pm q,a\pm pq$. For each of those $k-a$ is odd and, by going with the previous calculation backwards, $k-a\mid b-k^2$. Further, $k$ has parity opposite to that of $a$ (if $a$ is even, $k$ is odd and vice versa), and the same is true of $b$, so $b-k^2$ is even. It follows that $2(k-a)\mid b-k^2$, and hence $f(k)=\frac{b-k^2}{2k-2a}$ is an integer.
Edit: Let me assume $p<q$. Then of the eight values of $k$ above all are positive, except for $a-q,a-pq$. To get $f(k)$ positive, we must either have $k>a$ and $b\geq k^2$ or $k<a$ and $b\leq k^2$. The former is impossible, since it implies $b\geq (a+1)^2$, and this is easily seen to never hold - indeed, $b\leq 2a-1$.
Therefore we have $k<a$. This implies that $k=a-1$ or $k=a-p$, so $a-p$ is necessarily the value you seek for. In terms of $n$, you can't say anything more about $p$ than $3\leq p\leq\sqrt{n+1}-1$ (which happens when $q=p+2$), so $a-\sqrt{n+1}+1\leq k=a-p\leq a-3$. If you want a bound in terms of just $a,b$ you get $a-\sqrt{a^2-b+1}+1\leq k\leq a-3$ and those bounds are optimal.
