• + 1 comment

    The same modulus 8 solution in JavaScript/Node.js:

    function getXor(x) { let n = x % 8; if (n === 0 || n === 1) return x; if (n === 2 || n === 3) return 2; if (n === 4 || n === 5) return x + 2; return 0; }

    function xorSequence(l, r) { return BigInt(getXor(r)) ^ BigInt(getXor(l - 1)); }