
4. Find the sum of all 3-digit natural numbers which contain at least one odd digit and at least one even digit.


Solution: Let $X$ denote the set of all 3-digit natural numbers; let $O$ be those numbers in $X$ having only odd digits; and $E$ be those numbers in $X$ having only even digits. Then $X \backslash(O \cup E)$ is the set of all 3-digit natural numbers having at least one odd digit and at least one even digit.The desired sum is therefore

$$
\sum_{x \in X} x-\sum_{y \in O} y-\sum_{z \in E} z
$$

It is easy to compute the first sum;

$$
\begin{aligned}
\sum_{x \in X} x & =\sum_{j=1}^{999} j-\sum_{k=1}^{99} k \\
& =\frac{999 \times 1000}{2}-\frac{99 \times 100}{2} \\
& =50 \times 9891=494550
\end{aligned}
$$

Consider the set $O$. Each number in $O$ has its digits from the set $\{1,3,5,7,9\}$. Suppose the digit in unit's place is 1 . We can fill the digit in ten's place in 5 ways and the digit in hundred's place in 5 ways. Thus there are 25 numbers in the set $O$ each of which has 1 in its unit's place. Similarly, there are 25 numbers whose digit in unit's place is $3 ; 25$ having its digit in unit's place as $5 ; 25$ with 7 and 25 with 9 . Thus the sum of the digits in unit's place of all the numbers in $O$ is

$$
25(1+3+5+7+9)=25 \times 25=625
$$

A similar argument shows that the sum of digits in ten's place of all the numbers in $O$ is 625 and that in hundred's place is also 625 . Thus the sum of all the numbers in $O$ is

$$
625\left(10^{2}+10+1\right)=625 \times 111=69375
$$

Consider the set $E$. The digits of numbers in $E$ are from the set $\{0,2,4,6,8\}$, but the digit in hundred's place is never 0 . Suppose the digit in unit's place is 0 . There are $4 \times 5=20$ such numbers. Similarly, 20 numbers each having digits $2,4,6,8$ in their unit's place. Thus the sum of the digits in unit's place of all the numbers in $E$ is

$$
20(0+2+4+6+8)=20 \times 20=400
$$

A similar reasoning shows that the sum of the digits in ten's place of all the numbers in $E$ is 400 , but the sum of the digits in hundred's place of all the numbers in $E$ is $25 \times 20=500$. Thus the sum of all the numbers in $E$ is

$$
500 \times 10^{2}+400 \times 10+400=54400
$$

The required sum is

$$
494550-69375-54400=370775
$$
