A
*
Lucky Number
*
is a positive integer whose digits, in base-10 notation, are only 4 or 7.

Find the number of occurrences of the digit 7 in base-10 notation of the
$2017^\text{th}$
smallest
*
Lucky Number
*
.

The answer is 6.

**
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.

Consider the following (recursive) map $f$ from the set of all lucky numbers (represented as strings) to string of binary numbers :

$f(4x) = \,'0'f(x) \\ f(7x) = \,'1'f(x) \\ f(4) =\, '0' \\ f(7) =\, '1'$

For example, $f(47) =\, '0'f(7) =\, '01'$ . Note that $f$ is both bijective and order preserving (assuming lexicographic ordering for strings).

Also, note that number of binary strings of length less than $n$ are $\sum_{r = 1}^{n - 1} 2^r = 2^n - 2$

So, if $k$ is the length of $f(\text{2017th smallest Lucky number})$ , then $2^k - 2 \leq 2017 \text{ and } 2^{k + 1} - 2 > 2017 \implies k = 10$

Hence, $\text{ 2017th Lucky number } = f^{-1} (\text{ binary representation of } \{2017 - (2^{10} - 2) -1\}) = f^{-1} ('1111100100') = 7777744744$