Base-p digit sum (source code)

= Base-p digit sum
{title2=$d_p(n)$}

If
$$
n=\sum_{r\geq0}\alpha_rp^r,
\qquad 0\leq\alpha_r<p,
$$
then the base-$p$ digit sum is $d_p(n)=\sum_r\alpha_r$. The <Legendre formula> can equivalently be written
$$
v_p(n!)=\frac{n-d_p(n)}{p-1}.
$$