<s>[INST] Prove that $W(n,\sum_{k=1}^{n}k^{2})=2(n-1)$ Let $F_{a}(n)$ be the digit sum of $n$ in base $a$,
define $W(a,b)=F_{a}(a^{\lceil\frac{\log{b}}{\log{a}}  \rceil}-b)$,
prove that $\displaystyle\ W(n,\sum_{k=1}^{n}k^{2})=2(n-1)$ if $n−1 \in 6\mathbb{N} \pm 1$.
 [/INST] Let
\begin{align}
&a=n&
&b=\sum_{k=1}^nk^2=\frac{n(n+1)(2n+1)}6
\end{align}
We have
$$\frac{a^3}3\leq b\leq\frac{a^3}3+a^2$$
from which
$$2<\frac{\log(b)}{\log(a)}<3$$ hence $\lceil\log(b)/\log(a)\rceil=3$ and $W(a,b)=F_a(a^3-b)$.
Moreover, if $b=d_0+d_1a+d_2a^2$ with $0\leq d_i\leq a-1$ then
$$a^3-b=(a-d_0)+(a-d_1-1)a+(a-d_2-1)a^2$$
Since $a\nmid b$, we have $d_0\neq 0$, hence
\begin{align}
W(a,b)
&=(a-d_0)+(a-d_1-1)+(a-d_2-1)\\
&=3a-(d_0+d_1+d_2)-2\\
&=3n-2-F_n(b)
\end{align}
and it remains to show $F_n(b)=n$.
If $n=6q$, then $b=q+(3q)n+(2q)n^2$, hence $F_n(b)=q+3q+2q=6q=n$.
If $n=6q+2$, then $b=(1+3q)+qn+(1+2q)n^2$, hence $F_n(b)=(1+3q)+q+(1+2q)=2+6q=n$.
</s>