TITLE: Can $pk+1$ divide $(p-k)^2$?
QUESTION [8 upvotes]: Let $p>3$ be a prime, $0<k<p$. Then is it possible that $pk+1\mid(p-k)^2$?
For $k=1$, since $(p-1)^2\equiv(-2)^2\equiv4\pmod{p+1}$, and $p>3$, this is not possible.
And if $pk+1\mid(p-k)^2$ then $k^2-3pk+p^2-1\geq0$, so $k\leq\frac{3p-\sqrt{5p^2+4}}2$.

This arises from another question. I am running out of ideas, so any help is sincerely appreciated, thanks in advance.

REPLY [5 votes]: Claim: If $a,b$ are positive integers and $q(a,b) := \frac{(a-b)^2}{ab+1}$ is an integer, it is a square number. This may be proved by Vieta jumping as follows: 
Let $k \geqslant 1$ be an integer, which is not a square. Assume that there are positive integers $A,B$ such that $q(A,B) = k$, and choose $A$ and $B$ so that $A \geqslant B$ and that $A+B$ is minimal. 
By expanding the statement $q(A,B) = k$, we find that $A$ is a solution to the quadratic $X^2 - B(2+k)X + B^2 - k = 0$. Since its discriminant is positive, there is another solution $C$ which may be expressed using Vieta's formulas as
\begin{align*}
C = B(2+k) - A = \frac{B^2 - k}{A} < A.
\end{align*}
The first representation of $C$ shows that it's an integer, and the other one shows that it's non-zero, since $k$ isn't a square. Also, since 
\begin{align*}
\frac{(C-B)^2 }{CB + 1} = k > 0,
\end{align*}
we see that $C$ has to be a positive integer. But then 
\begin{align*}
C+ B < A+B,
\end{align*}
contradicting the minimality of $A+B$.   $\blacksquare$
This means that if $q(p,t)$ is an integer, there is some integer $m$ with
\begin{align*}
q(p,t) = \frac{(p-t)^2}{pt + 1} = m^2,
\end{align*}
and by estimating $q(p,t)$ (using $1 \leqslant t \leqslant p-1$) it's easy to see that $m^2 \leqslant p-1$. 
Rearranging this equation gives 
\begin{align*}
p^2 - 2pt + t^2 = m^2 p t + m^2,
\end{align*}
so 
\begin{align*}
p \mid p^2 - (2 + m^2) p t  = m^2 - t^2 = (m-t)(m+t).
\end{align*}
Given the bounds on $m$ and $t$, the only possibilities here are that $m = t$ or that $m+t = p$. In the first case, our equation is
\begin{align*}
p^2 - 2pt + t^2 = t^3 p + t^2 &\Leftrightarrow p^2 - 2pt - t^3 p = 0 \\
&\Leftrightarrow p  = 2t + t^3
\end{align*}
so $t \mid p$, meaning $t = 1$, so $p = 3$, which is impossible. In the second case, we have $m = p-t$, so our equation is
\begin{align*}
(p-t)^2 = p^2 - 2pt + t^2 = (p-t)^2 p t + (p-t)^2 &\Leftrightarrow 1 = pt + 1,
\end{align*}
forcing $t = 0$, which is impossible.