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 smallest Lucky Number .
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 ( 4 x ) = ′ 0 ′ f ( x ) f ( 7 x ) = ′ 1 ′ f ( x ) f ( 4 ) = ′ 0 ′ f ( 7 ) = ′ 1 ′
For example, f ( 4 7 ) = ′ 0 ′ f ( 7 ) = ′ 0 1 ′ . 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 r = 1 ∑ n − 1 2 r = 2 n − 2
So, if k is the length of f ( 2017th smallest Lucky number ) , then 2 k − 2 ≤ 2 0 1 7 and 2 k + 1 − 2 > 2 0 1 7 ⟹ k = 1 0
Hence, 2017th Lucky number = f − 1 ( binary representation of { 2 0 1 7 − ( 2 1 0 − 2 ) − 1 } ) = f − 1 ( ′ 1 1 1 1 1 0 0 1 0 0 ′ ) = 7 7 7 7 7 4 4 7 4 4