Binary vs Decimal
Time limit1sMemory limit256 MB
Find the n-th positive integer whose decimal digits form a suffix of its binary representation.
- Level
Medium7 of 10
- Topics
- Number theory, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
A positive integer is bindecimal if its decimal representation is a suffix of its binary representation. Both representations are written without leading zeros.
For example, , and the decimal representation 10 matches the last two digits of the binary representation 1010, so 10 is bindecimal. On the other hand , and 1010 is not a suffix of 1111110010, so 1010 is not bindecimal. Neither is 42, because and 42 is not a suffix of 101010.
Find the -th smallest bindecimal number.
Input
The first and only line contains one integer . ()
Output
Print the -th smallest bindecimal number in decimal notation.
Hint
A binary representation uses only the digits 0 and 1, so the decimal representation of a bindecimal number also uses only 0 and 1. Here are the smallest numbers whose decimal representation contains only 0's and 1's.