Let $m\geq 2$ be a fixed integer.


Let
$$f(n):=\begin{cases}
mf\left(\frac{n}{m}\right),&\text{if $n\mod m = 0$;}\\
1,&\text{otherwise}
\end{cases}$$
then if we have
$$a(n):=\begin{cases}
1,&\text{if $n=0$;}\\
a\left(\frac{n}{m}\right)+a\left(n-f\left(\frac{n}{m}\right)\right),&\text{if $n\mod m = 0$;}\\
a\left(\left\lfloor\frac{n}{m}\right\rfloor\right),&\text{otherwise}
\end{cases}$$
and also
$$s(n):=\sum\limits\_{k=0}^{m^n-1}a(k).$$
In particular, $s(0) = 1$ and $s(1) = m$.


I conjecture that for $m > 2$
$$s(n)=(m+3)s(n-1)-(2m+1)s(n-2).$$
For a case $m=2$ we get Bell numbers.


Is there a way to prove it?


Similar questions:


* [Sum with Stirling numbers of the second kind](https://mathoverflow.net/questions/406738/sum-with-stirling-numbers-of-the-second-kind)
* [Pair of recurrence relations with $a(2n+1)=a(2f(n))$](https://mathoverflow.net/questions/406902/pair-of-recurrence-relations-with-a2n1-a2fn)
* [Sequence that sums up to INVERTi transform applied to the ordered Bell numbers](https://mathoverflow.net/questions/407290/sequence-that-sums-up-to-inverti-transform-applied-to-the-ordered-bell-numbers)
* [Sequences that sums up to second differences of Bell and Catalan numbers](https://mathoverflow.net/questions/407758/sequences-that-sums-up-to-second-differences-of-bell-and-catalan-numbers)



Recurrence for the sum
Let $n=m^tk$ where $m\nmid k$. Then $f(n)=m^t$. 
Furthermore, if $t>0$, then $f(n/m)=m^{t-1}$ and $n-f(n/m)=m^{t-1}(mk-1)$. It follows that $a(n)=a(m^{t-1}k)+a(m^{t-1}(mk-1))$ and further by induction on $t$,
$$
(\star)\qquad a(n)=\sum\_{i=0}^t \binom{t}{i} a\big(m^ik-\frac{m^i-1}{m-1}\big).
$$




---


**CASE $m>2$.** In this case, formula $(\star)$ reduces to
$$a(n) = a(k)+(2^t-1)a(k-1).$$


Let's analyze $s(n)$.
It is clear that for any $\ell\not\equiv 0\pmod{m}$, we have
$$\sum\_{k=0\atop k\equiv \ell\pmod{m}}^{m^n-1} a(k) = s(n-1)$$
and correspondingly
$$\sum\_{k=0\atop k\equiv 0\pmod{m}}^{m^n-1} a(k) = s(n) - (m-1)s(n-1)$$


Now we are ready to derive a recurrence for $s(n)$ by grouping the summation indices based on the power $m^t$ they contain:
\begin{split}
s(n) &= 1 + \sum\_{t=0}^{n-1} \sum\_{k=1\atop k\not\equiv 0\pmod{m}}^{m^{n-t}-1} \left(a(k) + (2^t-1)a(k-1)\right) \\
&=1 +\sum\_{t=0}^{n-1} \left((m-1)s(n-t-1) + (2^t-1)((m-2)s(n-t-1) + s(n-t)-(m-1)s(n-t-1))\right) \\
&=1 +\sum\_{t=0}^{n-1} \left((m-2^t)s(n-t-1) + (2^t-1)s(n-t)\right) \\
&=2 - 2^n + \sum\_{t=1}^n (2^{t-1}+m-1)s(n-t).
\end{split}


Restating the above recurrence in terms of the generating function $S(x):=\sum\_{n\geq 0} s(n)x^n$, we have
$$S(x) = \frac{2}{1-x} - \frac{1}{1-2x} + \left(\frac{x}{1-2x} + \frac{(m-1)x}{1-x}\right)S(x).$$
That is,
$$S(x) = \frac{1-3x}{1 - (m+3)x + (2m+1)x^2},$$
from where the required recurrence follows instantly.




---


**CASE $m=2$.** In this case, formula $(\star)$ takes form:
$$a(n)=a(k)+\sum\_{i=1}^t \binom{t}{i} a(2^{i-1}(k-1)).$$
It further follows that for $n=2^{t\_1}(1+2^{1+t\_2}(1+\dots(1+2^{1+t\_\ell}))\dots)$ with $t\_j\geq 0$, we have
\begin{split}
a(n) &= \sum\_{i\_1=0}^{t\_1} \binom{t\_1}{i\_1} \sum\_{i\_2=0}^{t\_2+i\_1} \binom{t\_2+i\_1}{i\_2} \sum\_{i\_3=0}^{t\_3+i\_2} \dots \sum\_{i\_\ell=0}^{t\_\ell+i\_{\ell-1}} \binom{t\_\ell+i\_{\ell-1}}{i\_\ell} \\
&=\prod\_{j=1}^\ell (\ell+2-j)^{t\_j}.
\end{split}


Grouping the summands in $s(n)$ by the number of unit bits, we have
\begin{split}
s(n) &= \sum\_{\ell=0}^n\ \sum\_{t\_1+t\_2+\dots+t\_{\ell}\leq n-\ell}\ \prod\_{j=1}^\ell (\ell+2-j)^{t\_j}\\
&= \sum\_{\ell=0}^n\ \sum\_{t\_1+t\_2+\dots+t\_{\ell}+t\_{\ell+1} = n-\ell}\ \prod\_{j=1}^{\ell+1} (\ell+2-j)^{t\_j}\\
&=\sum\_{\ell=0}^n [x^{n-\ell}]\ \prod\_{j=1}^{\ell+1} \frac1{1-jx} \\
&=\sum\_{\ell=0}^n S(n+1,\ell+1) \\
&=B\_{n+1},
\end{split}
where $S(n+1,\ell+1)$ are Stirling numbers of second kind, and $B\_{n+1}$ is Bell number.


