1

Lets say that R=15 and L=8, then how can I efficiently find:

15 XOR 13 XOR 11 XOR 9

If R=20 and L=10, then it would be:

20 XOR 18 XOR 16 XOR 14 XOR 12 XOR 10

$1<=L<=R<=10^{15}$

This might be similiar Finding XOR of all even numbers from n to m but that only covers even numbers. If R is odd then it will be all odd numbers from R to L.

I asked this question on StackOverflow previously but it was marked as duplicate and the problem wasn't exactly the same as this one.

No Name
  • 165
  • 2
  • 3
    This question is essentially the same. Only the least significant bit may be different, and is determined by the number of odd values being XORed together. 15 XOR 13 XOR 11 XOR 9 = 14 XOR 12 XOR 10 XOR 8 – Daniel Mathias Jan 06 '22 at 00:56

0 Answers0