Hints and solutions to Look for a pattern #6

Determine the number of integers between 1 and 1000 that contain at least one 2 but no 3.


  • This is a pretty complicated counting problem. We want to count numbers like 245 and 622, because they have 2's as digits, but we don't want 532 or 392 because they have 3's in addition to their 2's.
  • You might try a simpler version of this first (like integers between 1 and 100), or variations (which numbers have 2's, but forget about the 3's, or without 3's and forget about the 2's).
  • What pattern shall we look for? Let's try doing the problem for numbers between 1 and 10, then between 1 and 100.
  • There are 10 numbers between 1 and 10. Only one of them contains a 2 (namely, 2 itself), and there's no 3 here.
  • There are 100 numbers between 1 and 100 - Let's list all of the ones that have a digit "2" -- 2, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 42, 52, 62, 72, 82, 92. There are 19 numbers here, but two of them have "3"s. So there are 17 numbers between 1 and 100 that contain at least one 2 but no 3.
  • Let's think about how to do this without writing all the numbers down. We certainly don't want to have to do that for 1 to 1000!
  • How many numbers between 1 and 100 have no 3 in them? If we're not allowing any 3's then there are 9 ways to pick the tens digit and 9 ways to pick the ones digit (we're allowing numbers like 03 for 3 etc). So there are 81 numbers between 1 and 100 with no 3's.
  • Next, let's figure out how many of these have at least one 2. Actually, it's easier to do the opposite -- to figure out how many of the 81 numbers with no 3's have no 2's either. Then we can subtract this number from 81 to get the number of numbers with no 3's that have at least one 2.
  • So, how many numbers between 1 and 100 have no 2's and no 3's? Now there are 8 ways to pick the tens digit and 8 ways to pick the ones digit, which gives us 64. So we're not interested in 64 of the 81 numbers with no 3's -- this leaves 17 that have at least one 2 but no 3's, just as we calculated above. Notice, this is 92 - 82.
  • Now we're ready to tackle the numbers from 1 to 1000.
  • How many numbers from 1 to 1000 have at least no 3's in them? Just as for the 1 to 100 case, we have 9 ways to pick the hundreds digit, 9 ways to pick the tens digit and 9 ways to pick the ones digit. This makes 93 = 729 numbers with no 3s.
  • Now we want to "throw away" the ones that don't have any 2's either. Again as before, there are 8x8x8 of these (since there are now 8 ways to pick the hundreds digit, 8 to pick the tens and 8 to pick the ones).
  • So we're left with 93 - 83 = 729-512 = 217 numbers with at least one 2 but no 3's.
  • You might want to try numbers from 1 to 10,000 next.