Base-2 Palindromes
InterviewTime limit1sMemory limit256 MB
Find the M-th positive integer whose binary representation reads the same forward and backward and print it in decimal.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Math
- Solved
- No attempts yet
Problem
A positive integer is a base- palindrome when the base- representation of reads the same forward and backward. For example, the decimal number 7 is a single digit in every base 8 or larger, so it is a palindrome in all of those bases. It is a palindrome in base 2 () and in base 6 () as well, but not in base 3 (), base 4 (), base 5 (), or base 7 (). Written in base 10 and sorted from smallest, the base-2 palindromes begin 1, 3, 5, 7.
Find the -th base-2 palindrome and print it in base 10.
Input
The first line contains one positive integer written in base 10. ()
Output
Print the -th base-2 palindrome in base 10 on the first line.