Divisibility rule (source code)

= Divisibility rule

= Divisibility test
{synonym}

A <divisibility rule> tests whether one <integer> divides another by replacing it with a simpler equivalent condition. For a base-$b$ expansion $N=\sum_i d_ib^i$, the congruence class of $b$ modulo the candidate divisor determines a rule.

In base ten, $10\equiv1\pmod9$, so $N$ and its digit sum have the same residue modulo nine. Also $10\equiv-1\pmod{11}$, so divisibility by eleven is equivalent to divisibility of the alternating digit sum. For example, $121$ passes because $1-2+1=0$. These tests follow from <modular arithmetic> and depend on the numerical base.