Counting triples $(a_1, a_2, a_3)$ such that $0\leq a_i\leq 9$ and $a_1+a_2+a_3$ is divisible by $3$ [closed]

Here is a slick solution:

Fact: A number is divisible by three if and only if the sum of its digits is divisible by three.

Thus $3|a_1+a_2+a_3$ iff $3| a_1a_2a_3$ (with the digits joined together implied). There are $999/3+1=334$ nonnegative multiplies of 3 less than $1000$. So the answer is C


In order for something to be divisible by $3$, it has to have remainder $0$ when divided by $3$ or $0\mod 3$

If you want to add numbers, you can just take their modulus, add those, and then take the modulus of that result. In your case, our sum will be $0\mod 3$ if we are adding

  1. $3$ numbers that are $0\mod 3$
  2. $3$ numbers that are $1\mod 3$
  3. $3$ numbers that are $2\mod 3$
  4. $1$ number of each $0,1,2 \mod 3$

The numbers that are $0\mod 3$ are $\{0,3,6,9\}$, the ones that are $1$ are $\{1,4,7\}$, and the ones that are $2$ are $\{2,5,8\}$. From here it is a simple permuation calculation since order of triples matters.