For a given sequence consisting of a fraction of 2 functions, is there a way to know how many entries are of integer value? For a given sequence $\frac{n^2+k^2}{2n+1}$ where $k$ is a given integer and $k > 0$, is there a way to calculate how many entries will be of integer value. Or, if that is not possible, know if it will ever be of integer value after a certain point.
For example:
The sequence $\frac{n^2+16}{2n+1}$ is of integer value for $n=2$ as well as for $n=32$.
Is there a way of knowing for certain that $n=32$ is the last entry of integer value?
 A: The exact algebraic answer is:
$$n\equiv \frac {p-1}{2}$$
where, $\thinspace p\mid 4k^2+1\thinspace .$
Here, I have no knowledge that the number of all the factors of $4k^2+1$ can be found by an algebraic formula that depends on $k\thinspace .$

To get the general solution to the problem, we usually apply (as far as I know) $2$ methods: subtracting a polynomial from a fractional expression that makes the numerator a constant and the Discriminant method.  Both methods yield the same result.  I prefer the $\Delta$ method.
You have:
$$\begin{align}&\frac{n^2 + k^2}{2n+1}=m, \thinspace m\in\mathbb Z\\
\implies &n^2-2nm+(k^2-m)=0 \\
\implies &\Delta_n=4m^2-4k^2+4m\\
&\thinspace\thinspace\thinspace\thinspace\thinspace\thinspace\thinspace\thinspace=(2m+1)^2-(4k^2+1)\\
&\thinspace\thinspace\thinspace\thinspace\thinspace\thinspace\thinspace\thinspace=x^2, \thinspace x\in\mathbb Z\thinspace.\end{align}$$
This leads to the factorization:
$$(2m-x+1)(2m+x+1)=4k^2+1$$
Since the polynomial is symmetric with respect to the sign of $x$, without loss of generality, we have:
$$n=\frac{2m-x}{2}\implies x=2m-2n$$
This yields, unique factorization in terms of $m$ and $n\thinspace :$
$$\bbox[5px,border:2px solid #C0A000]{\begin{align}(2n+1)(4m-2n+1)=4k^2+1\end{align}}$$
We observe that, the number of pairs $(m,n)$ will vary depending on what the odd factors of $4k^2+1$ are.
Let $p=2n+1$ be a possible factor of $4k^2+1\thinspace.$
Then we have:
$$\begin{align}&p(4m-p+2)=4k^2+1\\
\implies &2m+1=\frac {4k^2+p^2+1}{2p}\end{align}$$
Since, $p$ is odd and $2p\mid 4k^2+p^2+1$, this implies that we need only the restriction $4\not\mid 4k^2+p^2+1\thinspace .$
Thus, we obtain the necessary and sufficient condition: $p\mid 4k^2+1\thinspace.$
Finally, we can write a closed-form formula for $n$, that includes all possible numbers:
$$n\equiv \frac {p-1}{2}$$
where, $\thinspace p\mid 4k^2+1\thinspace .$
This completes the answer.
A: I don't have an answer, but here are my thoughts. Let $p$ be an integer entry in the sequence,
$$p = \frac{n^2 + k^2}{2n+1}$$
We can then rearrange to form a quadratic equation for $n$, for given $k,p$
$$n^2 + k^2 = p(2n+1)$$
$$n^2 - 2pn + (k^2 - p) = 0$$
For there to be solutions, the discriminant should be non-negative. But moreover, since $n$ is also integer, the discriminant should also be a perfect square, giving
$$ p^2 - k^2 + p = q^2 $$
So for any $k$, there must exist integers $p,q$ satisfying the above equation for integer terms in the sequence. If you can determine the integer combinations of $p,q$ that satisfy above, that should tell how many integer terms there are in the original sequence and what terms they are.
