Four digit numbers containing a 2 and a 5

cb220

New member
Joined
Nov 28, 2012
Messages
1
Hi, I'm having troubles with this counting problem:

How many numbers between 1000 and 9999 have at least one digit that is a 2 AND at least one digit that is a 5?

I'm thinking I need to take the total amount of numbers (9000) and subtract from it:
a) The numbers with 2 but not 5, plus
b) The numbers with 5 but not 2

The problem is I'm not sure how to calculate (a) and (b). I was thinking I could do it like so:
a) Case 1: 2 is the first digit, then: (1 * 9 * 9 * 9) = 729
Case 2: 2 isn't the first digit, so it has 3 possibilities in the last 3 digits, then: (8 * 3 * 9 * 9) = 1944
Then, 729 + 1944 = 2673 the total for (a).
b) Essentially the same process, just for 5 instead of 2 so result should be the same: 2673.

So then, 9000 - 2673 - 2673 = 3654 numbers with at least one 2 and at least one 5. But something about the way I got (a) and (b) feels off to me, so I think my answer is wrong. Could somebody help me out with this problem please? Thanks in advance.
 
Hi, I'm sure you've figured this out by now, but here's a way to think it through:

Break it down into two pieces:

First, for all numbers that don't start with 2 or 5 (i.e. not 2XXX or 5XXX). For example, take 7XXX. Now, we want to fill at least two of the Xs with 2 and 5.

There are C(3,2)=3 ways to choose two of the Xs. If you are not familiar with C, this is a simple case you can see for yourself: 7*XX, 7X*X, 7XX* are the ways you can do this. Then we want to "fill" the Xs with 2 and 5. Either 2 can go first, or 5 can go first, so there are two ways to place the numbers, for a total of 3*2=6 ways to place 2 and 5. Written out, it looks like:

7*25
7*52
72*5
75*2
725*
752*

Now we want fill out the * space, which can be any number EXCEPT 2 and 5 (because we will cover that case in a bit). There are 8 such numbers (0-9, minus 2 and 5). Therefore, there are 3*2*8 = 48 total numbers, starting with 7, and including ONE 2 and ONE 5.

Now, suppose we want to fill all three Xs in 7XXX with at least one 2 and at least one 5. There is obviously only one way to choose all three Xs (in proper notation, C(3,3)=1). We can fill these three positions with either 2,2,5 or 2,5,5, and there are three ways to order each (i.e., 225, 252, 522 and 255, 525, 552). Therefore, there are 1*6 ways to fill 7XXX with at least one 2 and at least one 5 in all the Xs.

Add these together, and you get 54 numbers starting with 7 that include at least one 2 and at least one 5. 7 was just a placeholder, and can be any of 1-9, but not 2 or 5 (yet), so there are 7*54 = 378 such numbers that DO NOT start with 2 or 5.

================

Now, what if they start with 2 or 5? The calculations are almost identical. Take 2XXX as an example. Now, it is possible to choose just a single X to be a 5, and the condition is satisfied. There are C(3,1) = 3 ways to choose an X (2X**, 2*X*, 2**X), and only one way to place 5 in that X, so there are 3 such numbers. As before, we want to fill the *s with numbers 1-9, minus 2 and 5, so there are 8 ways to fill each *. The total is 3*8*8 = 192 (3 to choose a place for 5, and 8*8 = 63 ways to fill the two remaining *s). So, there are 192 numbers that start with 2 and contain a single 5.

If we choose two Xs as before in the 7 example, we can fill the two Xs with 25, 52, or 55. To extend the previous example,

7*25
7*52
72*5
75*2
725*
752*

7*55
75*5
755*

The last three are the new cases. Again, we fill the * with any 8 numbers from 0-9 (minus 2 and 5), so there are 9*8 = 72 numbers that start with 2 and include AN ADDITIONAL 2 and ONE 5.

Finally, if we choose three Xs as before, instead of filling the Xs with 225,252,522,255,525, or 552, we can also include 555, since 2 is already in the first position. So, following the logic as before, there are 7 numbers that start with 2, and contain all 2s and 5s (and at least one of each).

So, there are 192 + 72 + 7 = 271 numbers starting with 2 and containing at least one 2 and at least one 5.

It is easy to see that the example above with 2XXX is exactly mirrored by 5XXX.

=====================

For the grand total, we see:

378 numbers that DO NOT start with 2 or 5
271 numbers starting with 2 and containing at least one 2 and at least one 5
271 numbers starting with 5 and containing at least one 2 and at least one 5
Total is 378 + 2*271 = 920

I know this post is kind of long, but the reasoning is very simple. The most important thing is to be systematic!
 
Top