Consider all the positive integers up to $10000000000 $ in which every digit is $0$ or $2$. the total number of $0$s among their digits

combinatoricsproblem solving

Consider all the positive integers up to $10000000000 $ in which every digit is $0$ or
$2$. What is the total number of $0$s among their digits?

I tried using the stars and bars method where
The $0$S were stars and digits were bars but it didn’t work because the possible number of digits is different

Taken from 2014 imc.

Best Answer

The interval $[10^r,10^{r+1}-1]$ contains all $(r+1)$-digit numbers. If a number in that interval consists of just $0$'s and $2$'s, then it must start with a $2$, followed by $r$ trailing digits. The number of such numbers is $2^r$, so the total number of trailing digits is $r2^r$; and by symmetry exactly half of the trailing digits are $0$, giving a total of $r2^{r-1}$ $0$'s.

Now just add up $r2^{r-1}$ for $0\le r\le 9$. (If you don't want to do this by hand, you will find tips for summing the series here, but doing it by hand is probably just as fast.)