For prime numbers $p_n$ it holds $m\equiv p_n^2\pmod {p_{n+1}}\implies$ $m$ is a square

For all $n\notin\{4,9,30\}$ it holds that if $m\equiv p_n^2\pmod {p_{n+1}}$ where $0 \leq m < p_{n+1}$, then $m$ is a square.

Tested for $n<1,000,000$.

The only exceptions seems to be $p_4=7$, $p_9=23$ and $p_{30}=113$.

Would like help to prove, explain or contradict this.

• What's the question? Obviously $p_n^2$ is a square. – lulu Feb 9 '18 at 20:58
• I suspect the OP is considering "mod" as a binary operation rather than as a ternary predicate.... – Lord Shark the Unknown Feb 9 '18 at 21:01
• @LordSharktheUnknown Sorry? Not following, – lulu Feb 9 '18 at 21:02
• @Lehs of course it is. It is the square of $p_4$. – lulu Feb 9 '18 at 21:02
• @Lehs Indeed. People who use "mod" as a binary operation are on my little list :-) – Lord Shark the Unknown Feb 9 '18 at 21:06

This is true if either $p_n^2<p_{n+1}$ (obviously) or if $(p_{n+1}-p_n)^2<p_{n+1}$ (because these two squares are congruent mod $p_{n+1}$, since $(-1)^2\equiv 1$). Since a number only has two square roots (or none) modulo a prime, these are the only possibilities.
• Oppermann says there is a prime between $n^2$ and $n^2-n$ for integer $n$, whereas what we need is a prime between $p$ and $p-\sqrt p$. So they are not quite the same, and it's technically possible that if Oppermann's conjecture was only barely true that there would be more counterexamples than this. But it seems likely that it's true with lots to spare as you go higher up. – Especially Lime Feb 9 '18 at 21:21
• e.g. Opperman says there is a prime between $121-\sqrt{121}$ and $121$, which there is. But what we'd need is a prime between $127-\sqrt{127}$ and $127$, which there isn't. – Especially Lime Feb 9 '18 at 21:23
• Note that if $k^2\equiv p_n^2$ mod $p_{n+1}$ then $(k-p_n)(k+p_n)\equiv 0$, and since $p_{n+1}$ is prime it follows that $k\equiv p_n$ or $k\equiv p_{n+1}-p_n$. – Especially Lime Feb 12 '18 at 6:37