Why can't $p^p-(p-1)^{p-1}=n^2$ be a square?

Let $p$ be a prime number. Show that $p^p-(p-1)^{p-1}$ can't be a square.

In other words, there is no $n\in\mathbb{N}^{+}$ such that $$p^p-(p-1)^{p-1}=n^2.$$

• Answers below tell you quickly that $p$ would have to be $1$ mod $4$. In fact, $p$ would have to be $1$ mod $8$. It's clear that $p^p-(p-1)^{p-1}$ is odd. The only odd square mod $8$ is $1$. So $p^p-(p-1)^{p-1}\equiv 1$. But since $(p-1)$ is even, $8$ divides $(p-1)^{p-1}$ (check $p=3$ separately). So you have $p^p\equiv 1$. Since $p$ is odd, $p^p\equiv p$. So $p\equiv1$ mod $8$. – alex.jordan Nov 2 '15 at 7:55
• There may be some interest in Boyd, Martin, and Thom, Squarefree values of trinomial discriminants, LMS J. Comput. Math. 18 (2015), no. 1, 148–169, MR3303602, where the question of squarefree values of $n^n+(-1)^n(n-1)^{n-1}$ is discussed. – Gerry Myerson Nov 5 '15 at 23:21

Let $p=2m+1$. Then $p^p=((p-1)^m+ni)((p-1)^m-ni)$. Now, the prime factorization in the Gaussian integers is unique and no factor on the right is divisible by $p$, so the only logically possible case is $p=4k+1=x^2+y^2$ and $(p-1)^m+ni=(x+iy)^p$. Then $1\equiv (p-1)^m\equiv x^p\equiv x\mod p$, so $x=1$. However, in this case the real part on the LHS is divisible by $y$ and the real part on the RHS is congruent to $1$ modulo $y$, which is a clear contradiction.

• @user236182 $\pm i$ and $\pm 1$ are exact $p$-th powers, so why should I? – fedja Oct 31 '15 at 19:10
• I would explicitly prove $(p-1)^m+ni, (p-1)^m-ni$ are relatively prime in order to conclude they're both $p$'th powers. Why does them not being divisible by $p$ prove they're relatively prime? $p$ is not necessarily prime in $\Bbb Z[i]$, e.g. $5=(2+i)(2-i)$. – user236182 Oct 31 '15 at 19:13
• @user236182 Because having both $x+iy$ and $x-iy$ as a factor in any of them results in divisibility by $p$, which is not there (the real part is not divisible by $p$). It is not "relatively prime implies $p$-th powers" but "the two conjugate primes in the factorization of $p$ have to be completely separated, hence..." – fedja Oct 31 '15 at 19:15
• You wanted to make it short, so here are some explanations for others: $x+yi,x-yi$ are prime in $\Bbb Z[i]$ (you used this) because their norms are ordinary primes; the prime factorization in $\Bbb Z[i]$ is unique because it's a UFD (like $\Bbb Z[\sqrt{-2}]$ but unlike $\Bbb Z[\sqrt{-n}]$ for $n\ge 3$ (see here)). The units$\pm i, \pm 1$ are $p$'th powers, otherwise we'd need to check cases $(p-1)^m+ni=\pm i(x+yi)^p,\pm (x+yi)^p$; also $p\equiv 1\pmod{4}$ because $x^2+y^2\equiv \{0,1,2\}\pmod{4}$. – user236182 Oct 31 '15 at 20:13
• @user10676 First congruence: $m$ is even. Second congruence: all binomial coefficients ${p\choose k}$ except the two extremal cases $k=0,k=p$ are divisible by $p$ and $(iy)^p$ is purely imaginary. – fedja Nov 1 '15 at 15:59

$p=2$ gives $p^p-(p-1)^{p-1}=3$, which is not a square. All other primes are congruent to either $1$ or $3$, modulo $4$. I can prove that no $p$ of the latter type satisfies the given equation.

Take $p^p-(p-1)^{p-1}$ modulo $p$; we get $0-(-1)^{p-1}=-1$. Hence a solution can exist only if $-1$ is a square modulo $p$. This happens when the Legendre symbol $(\frac{-1}{p})=1$, but for $p\equiv 3\pmod{4}$, that is not the case, by one of the parts of the Law of Quadratic Reciprocity.

• It's wrong to claim "a solution exists exactly when $p\equiv 1\pmod 4$. The equation has no solutions. – user236182 Oct 26 '15 at 3:56
• @user236182, thanks fixed. And I disagree that this should be a comment; arguably this solves half of the question. – vadim123 Oct 26 '15 at 3:59
• If $p\ge 3$, then $p^p=(p-1)^{p-1}+n^2$ is only possible if $p\equiv 1\pmod{4}$ simply because if $p\equiv -1\pmod{4}$, then $p^p\equiv (-1)^p\equiv -1\equiv (p-1)^{p-1}+n^2\pmod{4}$, contradiction, because a sum of two squares if $0,1,2$ mod $4$. – user236182 Oct 28 '15 at 16:34
• I don't think this deserves a downvote, and yet I really feel this doesn't deserve the bounty for being the highest-rated answer. – Erick Wong Nov 4 '15 at 17:07
• @user236182 That doesn't make sense. Only answers posted during the bounty period are eligible for an automatic award, and if the bounty is given manually, the bounty starter is free to ignore the score of the answers anyway. – Daniel Fischer Nov 5 '15 at 14:51

The remaining case $p \equiv 1 \pmod 4$ left by vadim123's answer can be settled by a 2004 result of Ellenberg that there are no positive solutions to $A^4 + B^2 = C^p$ for any prime $p>211$. This was further sharpened by Bennett, Ellenberg and Ng to show that there are no positive solutions to $A^4 + B^2 = C^n$ for any $n > 3$: https://www.math.wisc.edu/~ellenber/BeElNgdraftFINAL.pdf

As is common nowadays, the above methods make use of the modularity theorem, so quite possibly this is massive overkill for this problem.

I have an alternative proof not relying on the Legendre symbol of the fact that only primes satisfying $p\equiv1\operatorname{mod}4$ can possibly satisfy the equation.

If $p=2$, then $2^2-1^1 = 3$ is obviously not a square.

If $p>2$, then $p$ is odd. Therefore, $(p-1)^{(p-1)} = m^2$ is a perfect square and we have that $$p^p = n^2 + m^2$$ is the sum of two squares. But in order for this to be true we must have $p\equiv1\operatorname{mod}4$, because if we had $p\equiv-1\operatorname{mod}4$, then $p^p\equiv-1\operatorname{mod}4$. But as every square is congruent to either $0$ or $1$ modulo $4$, $n^2+m^2$ is in $\{0,1,2\}$ modulo $4$, a contradiction (argument due to @user236182).

• We must have $p\equiv 1\pmod{4}$ simply because if we had $p\equiv -1\pmod{4}$, then $p^p\equiv (-1)^p\equiv -1\equiv n^2+m^2\pmod{4}$, contradiction, because $n^2+m^2\equiv \{0,1,2\}\pmod{4}$. The theorem you link to is a lot stronger and is difficult to prove. It uses Fermat's theorem on sums of two squares or if you actually see the proof in the page you gave, it uses the Legendre symbol too, and is a lot more complicated than vadim123's $\left(-1|p\right)=1\iff p\equiv 1\pmod{4}$. – user236182 Oct 28 '15 at 16:13
• This also doesn't solve the problem, or doesn't lead to an elementary solution. – user236182 Oct 28 '15 at 16:13
• @user236182, why are you so hostile to people trying to contribute to this problem? – vadim123 Oct 28 '15 at 16:21
• This does rely on the Legendre symbol, if you see the proof of the theorem 1.1 you link to. – user236182 Oct 28 '15 at 16:29
• @DanielRobert-Nicoud You should edit your answer (with proper attribution) to correct the false claim. The proof in the comments does not rely on Legendre symbol, but the proof in your answer certainly does. – Erick Wong Oct 29 '15 at 8:01