$m \in \{2,6,42,1806,...\} $ - a problem of sum-of-$m$'th powers modulo $m$ (continuing the work for an answer for a question here in MSE and also in MO)
I'm (re-)viewing the function 
$$ f(m) = \sum_{k=0}^{m-1} k^m $$ 
considering its residue modulo $m$:
$$ r(m) \equiv f(m) \pmod m $$
It is easy to see why for odd m 
$$ r(m) = 0 \qquad \text{  for odd } m$$
Not so easy is it for even m. 
I tried to determine for what m we get $$ r(m) = 1 $$ It seems highly nontrivial; and after some brute force it seems this is very rarely the case, and seemingly for $m_k$ where $m \in \{2,6,42,1806,?? \} $ but interestingly not for the next $m=3263442 $ when we follow that pattern.        
The recursive pattern says
$$ \begin{array} {} m_0=&= 2 & \to & r(m_0)=1 & 2 \in \mathbb P\\
   m_1=m_0 \cdot (m_0+1) &= 2 \cdot 3 & \to & r(m_1)=1 & 3 \in \mathbb P\\
   m_2=m_1 \cdot (m_1+1) &= 2\cdot 3 \cdot 7 & \to & r(m_2)=1 &  7 \in \mathbb P\\
   m_3=m_2 \cdot (m_2+1) &= 2 \cdot 3 \cdot 7 \cdot 43 & \to & r(m_3)=1 & 43 \in \mathbb P\\
   m_4=m_3 \cdot (m_3+1) &=2 \cdot 3 \cdot 7 \cdot 43  \cdot 1807 & \to & r(m_4)=1807 &  1807 \notin \mathbb P\\
   m_5=m_4 \cdot (m_4+1) &=m_4 \cdot 3263443 & \to & r(m_5)=?? & 3263443  \in \mathbb P\\
  \vdots
 \end{array} \\
$$
However, I could not compute the last entry $r(m_5)$ because the sum expression for $f(m_5)$ is too huge. Also it seems to be an interesting question to answer this analytically. 


*

*Q1: is $r(m_5) = 1$ ? 

*Q2: does the pattern continue, in the sense that if the cofactor is/is not prime, the residue is/is not 1?      

*Q3: are the other numbers $w$ outside of this pattern for which $r(w)=1$ ?



The sequence $2,3,7,43,1807,... $  is in the OEIS in different variants
The sequence $2,6,42,1806,...$  is also in the OEIS in different variants


[update] Ah I see now, that in a comment at OEIS-sequence A014117 Max Alekseyev states (Aug 2013) that this sequence is even finite - however it is not yet clear to me, whether my problem-definition and the OEIS'-definition match. So this problem has possibly been solved... 
 A: Quick answer: No for all three questions.
Explanation: Let us suppose $r(m)=1$. Let $p$ be a prime factor of $m$, then we must have $$1 \equiv f(m)=\sum_{k=0}^{m-1}{k^m} \equiv \sum_{j=0}^{\frac{m}{p}-1}{\sum_{k=0}^{p-1}{(k+jp)^m}} \equiv \frac{m}{p}\sum_{k=0}^{p-1}{k^m} \pmod{p}$$
Consider a primitive root $g \pmod{p}$, then $$\sum_{k=0}^{p-1}{k^m}=\sum_{k=1}^{p-1}{k^m}\equiv \sum_{i=0}^{p-2}{(g^i)^m} \equiv \begin{cases} \frac{1-(g^m)^{p-1}}{1-g^m} \equiv 0 \pmod{p}& p-1 \nmid m \\ \sum_{y=1}^{p-1}{1} \equiv -1 \pmod{p} & p-1 \mid m \end{cases}$$
Thus if either $p-1 \nmid m$ or $p^2 \mid m$, then we have $1 \equiv \frac{m}{p}\sum_{k=0}^{p-1}{k^m} \equiv 0 \pmod{p}$, a contradiction.
Therefore $p-1 \mid m$ and $p^2 \nmid m$.
This implies that $m$ must necessarily be squarefree, and $p \mid m \Rightarrow p-1 \mid m$. We immediately see that $m$ must be even, so write $m=2p_1p_2 \ldots p_k$, where $p_1<p_2< \ldots <p_k$, and $k \geq 0$.
Note that for $i \leq k$, we have $p_i \mid m \Rightarrow p_i-1 \mid m=2p_1p_2 \ldots p_k$. Since $0<p_i-1<p_i< \ldots<p_k$, we have $(p_i-1, p_ip_{i+1} \ldots p_k)=1$ so $p_i-1 \mid 2p_1p_2 \ldots p_{i-1}$.
If $k=0$, then $m=2$ works, since indeed $r(2)=1$.
If $k \geq 1$, then $p_1-1 \mid 2$ and $p_1>2$, so $p_1=3$. If $k=1$ this gives $m=6$, which works, since $r(m)=1$.
If $k \geq 2$, then $p_2-1 \mid 2p_1=6$ and $p_2>p_1=3$, so $p_2=7$. If $k=2$ this gives $m=42$, which works, since $r(42)=1$.
If $k \geq 3$, then $p_3-1 \mid 2p_1p_2=42$ and $p_3>p_2=7$, so $p_3=43$. If $k=3$ this gives $m=1806$, which works, since $r(1806)=1$.
If $k \geq 4$, then $p_4-1 \mid 2p_1p_2p_3=1806$ which has no solution for $p_4>p_3=43$. Thus we get no solution for $m$ when $k \geq 4$.
In conclusion, the only $m$ for which $r(m)=1$ are $2, 6, 42, 1806$.
