[Math] number of integers having at least one even digit

number theory

if we have a range specified (say $[A,B]$) then how can we find efficiently the number of integers in this range which have at least one even digit $(0,2,4,6,8)$? One way would be to iterate through all integers in this range and for each check the digits. However for large difference in values of $A$ and $B$ this method may not be suitable (say $A = 1$ and B = $10^{10}$) .

E.g if $A = 1$ and $B = 25$ then the required answer is $15$: $(2,4,6,8,10,12,14,16,18,20,21,22,23,24,25)$

Thanks.

Best Answer

Find (1) The number of integers in the range, and (2) the number of integers in the range having only odd digits. Then subtract.

Related Question