Find the n-th positive integer whose decimal digits form a suffix of its binary representation.
Medium7Number theoryBit manipulationBrute forceNo attempts yetTime limit1sMemory limit256 MBA positive integer is bindecimal if its decimal representation is a suffix of its binary representation. Both representations are written without leading zeros.
For example, 1010=10102, and the decimal representation 10 matches the last two digits of the binary representation 1010, so 10 is bindecimal. On the other hand 101010=11111100102, and 1010 is not a suffix of 1111110010, so 1010 is not bindecimal. Neither is 42, because 4210=1010102 and 42 is not a suffix of 101010.
Find the n-th smallest bindecimal number.
The first and only line contains one integer n. (1≤n≤10000)
Print the n-th smallest bindecimal number in decimal notation.
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.
| Decimal | Binary | Comment |
|---|---|---|
| 1 | 1 | 1st bindecimal number |
| 10 | 1010 | 2nd bindecimal number |
| 11 | 1011 | 3rd bindecimal number |
| 100 | 1100100 | 4th bindecimal number |
| 101 | 1100101 | 5th bindecimal number |
| 110 | 1101110 | 6th bindecimal number |
| 111 | 1101111 | 7th bindecimal number |
| 1000 | 1111101000 | 8th bindecimal number |
| 1001 | 1111101001 | 9th bindecimal number |
| 1010 | 1111110010 | Not a bindecimal number |
| 1011 | 1111110011 | Not a bindecimal number |
| 1100 | 10001001100 | 10th bindecimal number |