#CSPS2019A. [CSP-S2019] 格雷码
[CSP-S2019] 格雷码
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 to have exactly one bit different. Specifically, the first string and the last string are also considered adjacent.
One example of binary strings of length s sorted in Gray Code is: , , , .
There can be multiple Gray Codes of length . The following is an algorithm for generating one of the Gray Codes:
- 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 reverse order.
In short, Gray Code of length is formed by adding a prefix to sorted Gray Code of length , and adding a prefix to reversely sorted Gray Code of length , to obtain 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 is , .
- The first strings in Gray Code of length are: , . The last are: , . Combining them, we get , , , . The labels are .
Gray Code of length follows the same rule:
- It's known that Gray Code of length is , , , .
- The first strings in Gray Code of length are: , , , . The last are: , , , . Combining them, we get , , , , , , , . The labels are .
You are given and . Find the -th binary string (the string with label ) in Gray Code of length , generated by the algorithm above.
Input Format
The only line of the input contains two integers: and .
Output Format
Print a single binary string of length 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, , .