When is $1^n+2^n+3^n+4^n+\cdots+n^n$ a square number?

I've been thinking about such an interesting question these last few days. I wonder if anyone has studied it.

Question: Find all postive integers $n$ such that $$S(n)=1^n+2^n+3^n+4^n+\cdots+n^n$$ is a square number?

Here $n=1$ is clear and if $n=3$ then $S(3)=36=6^2$. Now I can't find any other $n\le 20$, so I conjecture these $n$ are the only two values.

• What have you done so far? Did you predict how often this should happen based on asymptotics? Check for obstructions (mod n)? Plug the sequence into OEIS? Mar 5 '18 at 13:42
• If $n=2^k s$ and $k>0$ is even, then $S(n)$ is divisible by $2^{k-1}$, but not by $2^k$, thus can not be a perfect square. Analogously, if $n=4k+2$, then $S(n)$ is congruent to $n/2=2k+1$ modulo 8, thus $k$ must be divisible by 4. Mar 5 '18 at 22:00
• oeis.org/A031971 (obtained plugging 4 terms 1, 5, 36, 354)
– YCor
Mar 5 '18 at 22:53
• I checked all $n \leq 4000$, and there were no new examples. Mar 7 '18 at 14:52
• By computing $S(n)$ efficiently mod $p$ for small $p$, I have verified that $S(n)$ is not a square for $4 \leq n \leq 10^{7}$. The most difficult $n$ was $n = 9676659$ for which $S(n)$ is a square mod $p$ for $3 \leq p \leq 149$. Mar 8 '18 at 18:16

This is not an answer, but I don't have enough reputation to comment. For large $n$, $S(n)\approx n^n.$ The density of square integers at $n^n$ is approximately $n^{-n/2}$. So one might expect that the number of $S(n)$ which are square is about $\sum_{\mathbb N} n^{-n/2} \approx 1.7788$.

• I believe $S(n)$ is better approximated by $\frac{e}{e-1}n^n$, but up to a constant the order of magnitude is right. Mar 5 '18 at 17:41
• And given that the OP checked up to $n=20$ and the fact that $\sum_{n\ge21} n^{-n/2}\approx 1.5\cdot 10^{-14}$, the chances of there being any other examples is vanishingly small. Mar 5 '18 at 18:41
• Denoting by $C=\dfrac{e}{e-1}$, one has $C^{-1}(\sum_{n>0}n^{-n/2})^{2}\approx 2$ . Is there a reason for this ? Mar 6 '18 at 0:44
• (Technical comment to take new developments into account: two commenters at 2018-03-07 14:52:58Z and 2018-03-07 16:30:52Z not only "checked up to $n=20$ but up to $n=5500$, and still did not find another example.) Mar 7 '18 at 18:08
• (but the argument also applies to the sequence $S_0(n){\bf =}n^n$, which is nevertheless a square more than half of the time). Mar 7 '18 at 18:24

An easy obstruction (mod 8). We can exclude all odd multiples of $4$, because for any $k\in\mathbb{N}$, $S(8k+4)=2\mod 4.$ (Reason: if $j$ is even, $j^{8k+4}=0\mod 4$, and if $j$ is odd, $j^{8k+4}=1\mod 4$, and there are $4k+2$ odd numbers from $1$ to $8k+4$).

• You can also exclude those values which lead mod 8 to anything other than 0,1, or 4. This takes out a few more numbers mod 16. Gerhard "Then Try Mod Three Next" Paseman, 2018.03.05. Mar 5 '18 at 19:16
• Exact, indeed $S(8k+6)=3\mod 4$ for all $k$, by a similar computation. Mar 5 '18 at 19:18
• "Then Try Mod Three Next" : this takes out 3 numbers mod 18. In fact, for any prime $p$, $S(n)\mod p$ is periodic with period $(p-1)p^2$. For p=5, this takes out 15 numbers mod 100. (Not sure if this way one can exhaust all n though) Mar 6 '18 at 0:23
• @PietroMajer no, only eventually periodic. For instance $\varphi(8)8^2=256$, but modulo 8 we have $S(2)\equiv 5$ while $S(258)\equiv 1$.
– YCor
Mar 7 '18 at 22:58
• We may exclude also odd multiples of $4^m$, see my comment to the question Mar 10 '18 at 8:02

A special case,

Thm 1:   if prime $\ p\equiv 3\$ mod $4,\$ then $\ 1^{p-1}+\ldots (p-1)^{p-1}\$ is not a square.

Not a real answer either, but this link may be relevant : Faulhaber's formula

In particular one could try to establish, following Pietro Majer and Gerhard Paseman, that a solution of the diophantine equation $S(n)=m^{2} =P_{n}(a)$ only occurs for odd values of $n$, where $a=n(n+1)/2$ and $P_{n}$ is the $n$-th Faulhaber polynomial.