Background
In undergraduate Abstract Algebra homework, for an integer $n$ with decimal representation $a_m a_{m-1} ... a_1 a_0$, I proved that
- $3$ divides $n \iff 3$ divides $\sum_{i = 0}^{m} a_i$, and
- $11$ divides $n \iff 11$ divides $\sum_{i = 0}^{m} (-1)^i a_i$.
Proofs of these facts can be found here and here, respectively.
My Question
For an arbitrary prime $p$, can we deterministically formulate a non-vacuous statement of the form
$$\forall n \text{ expressible as } n = a_m a_{m-1} ... a_0 \in \mathbb{N}, \text{ we have that } p \mid n \iff p \mid \sum_{i = 0}^{m} b_i a_i$$
(... where the trick of formulating this statement is coming up with the sequence $(b_i)_0^m$)? I am interested in additive structure to the primes, and I am wondering if this type of exercise could show some interesting structure.
Although, as Iab pointed out, this question turns out to be a duplicate, I think it is helpful to coalesce information from multiple sources into one clear answer. (At least, it is helpful to me.) This is my attempt to do that.
The type of thing I am asking for is called a divisibility rule. The previously linked Wikipedia article gives a general rule to test for divisibility by $D$ when $D$ ends in 1, 3, 7, or 9, as well as a general rule for $D$ when $D$ is prime.
It remains to be shown how we can handle $D$ ending in 0, 2, 4, 5, 6, or 8. But this is easy.