Cow IDs
InterviewTime limit1sMemory limit128 MB
Find the N-th smallest binary number that has exactly K one-bits and no leading zeros, then print it in binary.
- Level
Medium5 of 10
- Topics
- Combinatorics, Math, Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
Farmer John, a secret computer geek, labels every one of his cows with a binary number. Being a little superstitious, he only uses binary numbers that contain exactly one-bits (). As with any binary number, the most significant bit of a label is always (there are no leading zeros).
Farmer John hands out labels in increasing numeric order, beginning with the smallest valid label — the -bit number whose bits are all . He has lost track of his numbering and needs your help: determine the -th label he assigns ().
Input
One line containing two space-separated integers and .
Output
Output a single line containing the -th label written in binary — a string of the characters 0 and 1 with no leading zeros.
Note
Listing the binary numbers with exactly three -bits in increasing order gives The -th of these is .