A positive integer is called spooky if at least one of the numbers 13 or 31 occurs in at least one pair of consecutive digits in the integer. For example, the integers 13, 831, and 73138 are all spooky. How many spooky integers less than are there?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Let us count the complement. Let a n be the number of non-spooky numbers that end in 1 or 3 . Let b n be the number of non-spooky numbers that do not end in 1 or 3 . Then we have the following recurrences:
a n + 1 = a n + 2 b n
b n + 1 = 8 ( a n + b n )
Since a 1 = 2 and b 1 = 8 , we can obtain that a 4 = 1 7 4 6 and b 4 = 7 6 9 6 . Thus, our desired answer is 1 0 4 − ( 1 7 4 6 + 7 6 9 6 ) = 5 5 8 .