# 2005 PMWC Problems/Problem I7

## Problem

How many numbers are there in the list $1, 2, 3, 4, 5, \dots, 10000$ which contain exactly two consecutive $9$'s such as $993, 1992$ and $9929$, but not $9295$ or $1999$?

## Solution

We use casework:

Case 1: two digits

That's easy, one number.

Case 2: three digits

We can use PIE here:

Set A consists of all three digit numbers in the form 99a. 10 of those.

Set B consists of all three digit numbers in the form b99. 9 of those.

Set \$A \intersection B\$ (Error compiling LaTeX. ! Undefined control sequence.) is the number 999.

There are 10+9-1=18 total three digit numbers. But we have a problem: we have counted 999, and that has 3 nines, not 2. So we subtract that to get

17 numbers here.

Case 3: 4 digits

So the numbers are either in the form ab99, a99b, and 99ab. We can just use direct counting here:

ab99: 9 choices for a (it can be 9, but no 0), and 9 choices for b (it can't be 9) =81. a99b: 8 choices (it can't be 0 or 9), and 9 choices for b (it can be 0 here) =72 99ab: 9 choices for a and 10 choices for b gives us 90.

72+81+90=243

we add all three cases:

$1+17+243=\boxed{261}$