B :: Two-Way Carry Propagation
Time Limit: 1 Second Memory Limit: 32768 KB
In 1897, the mathematician L. Aguile invented a special operation (#) over the binary representation of integer numbers.
In its simple form, A#B is computed according to the following steps, where A is a non-negative integer number and B
is of the form 2k for some integer k (0 <= k <=7):
- Consider the 8-bit binary representation of the numbers A and B, and name them A' and B' respectively.
- Compute C = A' + B' in base 10 (i.e. 1+1=2). Assume c1c2c3c4c5c6c7 be the sequence of digits in C.
- Since the addition is done in base 10, there may be some digit ci = 2. For such a digit, change ci to 0, and add 1 to ci-1 and ci+1. In case i = 0, only add 1 to ci+1. You may assume that the input numbers are small enough that this case never happens for i = 7.
- The step 3 is repeated until there is no digit 2 in C, which is finally considered as the binary representation of A#B.
For example, if
A = 23 (binary 00010111), and B = 2 (binary 00000010), then the following sequence of numbers defines the value of C in successive stages of the above algorithm: 00010121 -> 00010202 -> 00010210 -> 00011020 -> 00011101 which is the number 29. The problem is to input A and B, and output A#B. All numbers are in expressed in base 10 and you must take care of the conversions to binary and vice versa.
Input
The input consists of several test cases. Each test case comes on a separate line containing two integer numbers A and B, separated by blanks, where A is between 0 and 255, and B = 2k for some 0 <= k <=7. You may assume that at every step during the computation of A#B as defined above, C fits in an 8-bit number. You may assume that there are no blank characters at the beginning or at the end of the lines. The input terminates with a single line containing two zero which should not be processed.
Output
For each test case, output a single line containing the number A#B in decimal.
Sample Input
23 2 7 1 64 16 0 0
Sample Output
29 11 80Submit
Source: Tehran, Asia Region - Regional 2011