<s>[INST] When will the sequence $k \mapsto A + Bk + k^2$ yield a perfect square? Consider the following sequence:
$$a(k) = A + Bk + k^2 ,$$
where $A$ and $B$ are both integers, and $A < B$ ($k$ is of course an integer variable, B is even).
Problem:
For which $k^*$ is $a(k^*) = r^2$ (in other words for which $k$ the given sequence will yield a perfect square)?
Thanks in advance for any advice.
 [/INST] By repeatedly replacing $k$ by either  $k-1,$ or repeatedly by $k+1,$ we can demand that $0 \leq B < 2.$ This will alter $A,$ let us now call it $C.$ This is simply Gauss reduction, if you think in terms of the quadratic form $f(k,j)=k^2 + B k j + A j^2.$
Two sub-problems only:
$$k^2 + C = u^2$$
$$ k^2 + k + C = v^2 $$
$k^2 + C = u^2$ becomes $u^2 - k^2 = C.$ There is at least one solution as long as $C \neq 2 \pmod 4.$ Then write $C = mn,$ with $m \equiv n \pmod 2,$ and then $u-k=m, u+k = n$
$ k^2 + k + C = v^2 $ becomes $4 k^2 + 4k + 4C = 4v^2, $ $4 k^2 + 4k + 1 +(4C - 1 ) = 4v^2, $ $ (2k+1)^2 + (4C-1) = 4v^2. $ Or $  (4C-1) = 4v^2 - (2k+1)^2  $ and. Write all factorings, including negative, for $4C-1 = mn,$ so that $m,n$ are both odd, agree $\pmod 2,$ so we can then solve $2v-2k-1 = m,$ $2v+2k+1 = n.$
</s>