Binary Encoding
InterviewTime limit1sMemory limit128 MB
Given m, output the truncated binary code for each integer from 0 to m-1 following the standard truncated binary encoding rules.
- Level
Easy3 of 10
- Topics
- Bit manipulation, Implementation, Math
- Solved
- No attempts yet
Problem
Binary encoding represents each integer from to using exactly bits, where every bit is or . The most significant bit is written first, and two codes are compared from left to right, from the most significant bit to the least significant one. Codes are assigned so that when the numbers are listed in ascending order, their codes are also in ascending order. For example, the binary encoding of the numbers to is:
Truncated binary encoding generalizes this to represent the integers from to , where need not equal for any . Unlike ordinary binary encoding, it may use a different number of bits for different numbers. Let be the smallest integer with . Then truncated binary encoding represents each number using either or bits. Some numbers use only bits, and this happens only when ; when the encoding is the same as ordinary binary encoding. Truncated binary codes are compared from left to right, just like binary codes.
Truncated binary encoding also satisfies the following rules:
- Smaller numbers use the same number of bits as, or fewer bits than, larger numbers.
- When the numbers are listed in ascending order, their codes are also in ascending order.
- The codes for the numbers to are all distinct.
- No code with bits is a prefix of any code with bits.
- The total number of bits used for the numbers to is minimal.
For example, the truncated binary encoding of the numbers to is:
Encode the numbers from to using truncated binary encoding.
Input
The input contains a single integer ().
Output
Print lines. For each from to , the line at position must contain the truncated binary code of the number , so the codes are printed in ascending order of the numbers they represent.