= Alternating digit sum
{title2=$\sum_j(-1)^j d_j$}
The alternating digit sum of a nonnegative integer in radix $b\geq2$ is
$$
A_b(n)=\sum_{j=0}^{k-1}(-1)^jd_j,\qquad n=\sum_{j=0}^{k-1}d_jb^j,
$$
with a positive sign on the units digit. Starting the signs from the opposite end can change the overall sign, so the convention should be stated.
Because $b\equiv-1\pmod{b+1}$, the positional expansion gives $n\equiv A_b(n)\pmod{b+1}$. This proves a divisibility test: $b+1$ divides the number exactly when it divides its alternating digit sum. In decimal notation, $1023$ has alternating sum $3-2+0-1=0$ and equals $11\cdot93$.
The rule differs from the ordinary <digit sum> test modulo $b-1$, which instead uses $b\equiv1$. Both follow from the same <modular arithmetic> principle of replacing the radix by its residue before evaluating the digit polynomial.
Back to article page