String Transmission
Bob has received a binary string of length N transmitted by Alice. He knows that due to errors in transmission, up to K bits might have been corrupted (and hence flipped). However, he also knows that the string Alice had intended to transmit was not periodic. A string is not periodic if it cannot be represented as a smaller string concatenated some number of times. For example, "0001", "0110" are not periodic while "00000", "010101" are periodic strings. Now he wonders how many possible strin
View Solution →A or B
Consider four numbers: , , , and . You must change at most bits in and to form the numbers and satisfying the equation . Here, the | symbol denotes the bitwise OR operation. Given sets of the numbers defined above, find and print the respective values of and on new lines; if no such value exists, print instead. If there are multiple solutions, make as small as possible; if there are still multiple solutions, make as small as possible. Input Format The first line contains an i
View Solution →2's complement
Understanding 's complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is , we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote down the 's complement representation for each -bit integer in the inclusive range from to . How many 's would you write down in all? For example, using an -bit byte rather than bit i
View Solution →Changing Bits
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set to , where and is least significant bit of . set_b idx x: Set to , where and is least significant bit of . get_c idx: Print , where and . Given , and a list of commands, create a string made of the results of each call, the only command that produces output. For example, and so the length of the numbers is . Print an answer string that contains the results of a
View Solution →XOR key
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of for given integers , and , such that, . Help Xorq implement this function. For example, , , and . We test each for all values of between and inclusive: Function Description Complete the xorKey function in the editor below. It should ret
View Solution →