#CSPS2019A. 格雷码
格雷码
Description
In daily routines, people prefer to sort binary strings of length lexicographically. For example, if we sort binary strings of length increasingly, we will get: , , , .
Gray Code is a special sorting method to sort binary strings of length . It requires adjacent binary strings has exactly one digit in differ. Specifically, the first string and the last string is also considered as adjacent.
One example of binary strings of length being sorted in Gray Code is: , , , .
There can be multiple Gray Code of length . The following is one of the algorithms to generate Gray Code:
- Gray Code of length contains two binary strings of length , with the order: , .
- The first binary strings in Gray Code of length can be generated by adding a prefix to Gray Code of length ( binary strings of length in total. ) sorted in order.
- The last binary strings in Gray Code of length can be generated by adding a prefix to Gray Code of length ( binary strings of length in total. ) sorted in reversed order.
In a word, Gray Code of length is formed by adding prefix to sorted Gray Code of length , and adding prefix to reversely sorted Gray Code of length , binary strings in total. Additionally, for the binary strings in Gray Code of length , we will label them from to in order.
Using this algorithm, Gray Code of length can be generated as follow:
- It's known that Gray Code of length are , .
- The first Gray Code are: , . The last are: , . Combining them we can get , , , . The labels are .
Gray Code of length follows the same rule:
- It's known that Gray Code of length are , , , .
- The first Gray Code are: , , , . The last are: , , , . Combining them we can get , , , , , , , . The labels are .
You are given , find the -th binary string in Gray Code of length , generated by the algorithm above.
Input Format
The only line of the input consists two integers: .
Output Format
Output a single binary string of length in one line denoting the answer.
2 3
10
3 5
111
Constraints
For of the data, ;
For of the data, ;
For of the data, ;
For of the data, , .