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.
 A: Here is the beginning of a systematic method in the case $B$ even, $B=2B'$:
"Complete the square" i.e., write your expression in the form 
$$A'+(B'+k)^2=s^2 \ \ \ \leftrightarrow \ \ \ A'=(s-k-B')(s+k+B')$$ 
where $A'=A-B'^2$.
You have now to adjust the two parameters $k$ and $s$, but it opens the way for a systematic search by computer.
A: This seems to be a quadratic Diophantine equation
$$
X^2 + B X - Y^2 + A = 0 \quad (*) \\ 
$$
in the unknowns $X, Y$ with $A, B, X, Y \in \mathbb{Z}$ and additional constraints
$$
A < B\\
B \bmod 2 = 0
$$
where the particular $Y$ is not of interest, just that it exists.
Here is a page with algorithm and calculator for $(*)$. It must then be checked if such solutions honor the additional constraints.
The later introduced condition, that $B$ is even, allows to transform $(*)$ into the simpler equation
$$
X^2 + B X - Y^2 + A = 0 \iff \\
(X + B/2)^2 - Y^2 + A - (B/2)^2 = 0 \iff \\
(X')^2 - Y^2 + (A - (B/2)^2) = 0 \iff \\
(X')^2 - Y^2 = N \quad (**)
$$
with $X' = X + B/2$ and $N = (B/2)^2 - A$.
This is called a generalized Pell's equation (the case $N=1$ is called a Pell's equation), see here.
A: 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.$
