• + 0 comments

    In C#:

    class Solution {

    static long getXor(long x)
    {
        long 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;        
    }
    
    // Complete the xorSequence function below.
    static long xorSequence(long l, long r) {
        return getXor(r) ^ getXor(l - 1);
    }