We know that, giving a number, by adding up each of its digit, and mod the result by 3, if the reminder is 0, then the number is a multiple of 3, otherwise, it's not.
This algorithm works for 9 too.
I am wondering do there have similar general algorithms to check other small prime numbers, e.g. 7 or 11?
Or, just that 3 and 9 are too special?
A number written with digits $d_n\ldots d_2 d_1 d_0$ in decimal notation means $$ 10^n d_n + \cdots + 10^2 d_2 + 10^1 d_1 + d_0 $$
Divisibility tests are generally based on working modulo the divisor and correcting for the effect of the $10^n$ factors of the sum.
Dividing by $3$ and $9$ are special because $10\equiv 1$ modulo $3$ or $9$, so the $10^n$ factors disappear completely. These are the only divisors with this property (except for $1$, which is trivial). For all other divisors, different digit positions contribute differently to the sum, and the divisibility rules are correspondingly more complicated to state.
(Well, actually the divisibility rules for $2$ and $5$ are even simpler because $10\equiv 0$ modulo $2$ or $5$, so all terms in the sum above except for $d_0$ vanish completely and you need only to look at the last digit).
In other bases than ten, say, base $b$, it is similarly simple to test for divisibility by $b-1$ -- or divisibility by any divisor of $b-1$. In base sixteen, for example, the sum-of-digits test works for divisibility by $3$ but not for $9$ (because $9$ does not divide fifteen). But it does work for divisibility by $5$ in that setting.
If you know programming, here is pseudocode for a generic divisibility test:
The nice shape of the tests for $D=3$ and $D=9$ are because in that case
w = (b * w) % Dis a no-op (because(b*w)%D == ((b%D)*(w%D))%Dalways andb%D==1) sowstays $1$ throughout the loop, unlike in other cases.The more complex divisibility tests for other divisors correspond to precomputing the sequence of
ws.