TITLE: Ways to check whether a number is multiple of another number.
QUESTION [8 upvotes]: 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?

REPLY [3 votes]: While there are motley divisibility tests derivable from $\,c\mid 10 a + b\iff c\mid ja+kb\,$ for small $\,j,k\,$ it is usually simpler and quicker to just use modular arithmetic (which, unlike said tests, has the benefit of computing the remainder, so may be used to check arithmetic, as in casting out nines). 
This universal method amounts to evaluating a radix polynomial in nested Horner form, using modular arithmetic. For example, consider evaluating a $4$ digit radix $10$ number modulo $7$. 
$$\begin{align} \rm\ d_3\ d_2\ d_1\ d_0 \rightarrow\ &\rm ((d_3\cdot 10 + d_2)\cdot 10 + d_1)\ 10 + d_0\\ \equiv\ &\rm (\color{#c00}{(d_3\cdot\ 3\ + d_2)}\cdot\ 3\ + d_1)\ \ 3\ + d_0\!\!\pmod{7}\end{align}\qquad$$   
because $\rm\ 10\equiv 3\,\ (mod\,\ 7)\:.\:$ Thus we can compute the remainder $\rm\ (mod\ 7)\ $ 
by repeatedly replacing the two leading digits $\rm \,d_k\,d_{k-1}\,$ by $\rm \ \color{#c00}{(d_k\cdot 3 +  d_{k-1})}\ {\rm mod}\ 7.\,$  For example
$\rm\qquad\qquad\qquad\qquad\phantom{\equiv} \color{#C00}{4\ 3}\ 2\ 1\ 1$
$\rm\qquad\qquad\qquad\qquad\equiv\phantom{4} \color{green}{1\ 2}\ 1\ 1\quad $ by $\rm\quad \color{#C00}4\cdot 3 + \color{#C00}3\ \equiv\ \color{green}1 $
$\rm\qquad\qquad\qquad\qquad\equiv\phantom{4\ 3} \color{royalblue}{5\ 1}\ 1\quad $ by $\rm\quad \color{green}1\cdot 3 + \color{green}2\ \equiv\ \color{royalblue}5 $
$\rm\qquad\qquad\qquad\qquad\equiv\phantom{4\ 3\ 5} \color{#b0f}{2\ 1}\quad $ by $\rm\quad \color{royalblue}5\cdot 3 + \color{royalblue}1\ \equiv\ \color{#b0f}2 $
$\rm\qquad\qquad\qquad\qquad\equiv\phantom{4\ 3\ 5\ 2} 0\quad $ by $\rm\quad \color{#b0f}2\cdot 3 + \color{#b0f}1\ \equiv\ 0 $
Hence $\rm\ 43211\equiv 0\:\ (mod\ 7),\:$ indeed $\rm\ 43211 = 7\cdot 6173$ 
Generally the modular arithmetic is simpler if one uses a balanced system of representatives, e.g. $\rm\: \pm\{0,1,2,3\}\ \:(mod\ 7)\:.$ Notice that for modulus $11$ or $9\:$ the above  method reduces  to the well-known divisibility tests by $11$ or $9\:$ (a.k.a. "casting out nines" for modulus $9$).