4 ms·
There are at most 2 solutions: if m XOR d = a then either m+d = a or m+d = a+N. With the combination of m-d = b, you will find m and d. If both of them satisf
by biobot 15y ago
There are at most 2 solutions:
if m XOR d = a then either m+d = a or m+d = a+N.
With the combination of m-d = b, you will find m and d.
If both of them satisfied ( remember m and d are bounded by 1 and N) then we actually have two solutions.
- deleted 15y ago[deleted]
- pedrocr 15y agoHere's a counterexample. Sequence is [1, 2, 3, 4, 6, 6, 7, 8, 9, 10] so m = 5 and d = 6 diff = 5-6 = -1 xor = 5^6 = 3 1-2 = -1 1^2 = 3 5-6 = -1 5^6 = 3 9-10 = -1 9^10 = 3 So three different combinations, within N, that obey the two constraints
- biobot 15y agoMake sense! That fails my solution!
- biobot 15y agoOK. I think I find a way around. Assume d XOR m = a. Find k = position of the first bit (from MSB to LSB) in a. Then d + m can be in [a + 2^(k+1),a + 2^(k+2),...,a + 2^63]. We will have less than 63 cases. In each case, after we find d and m, make sure they are in range and then linear test. So in the end, we may need to run at most 63+3 = 66 N. But it still linear though.