• + 0 comments

    This is my Own Signature Solution!!! I spent 4 days just for this, and it surpassed the editorial's speed. The implementatoin is straightforward and highly intuitive. Hope you like it.

    include

    using namespace std;

    int main(){ int t; scanf("%d", &t); long long a, b, dts, mod, ret;

    while(t--) {
        scanf("%lld %lld", &a, &b); 
    
        ret = 0;
    
        //leading partial block 
        mod = a % 4;
        if(mod == 1) { ret = a + 1; a += 3; }//ret = a + 1 is key here, which reduces computational steps 
        else if(mod == 2) { ret = a + 1; a += 2; } 
        else if(mod == 3) { ++a; }
    
        //Full 4-blocks 
        dts = b - a + 1; 
        mod = dts / 4; 
        if(mod % 2 > 0) ret ^= 2; //xOr results in 2. 
    
        //Trailing partial blocks 
        mod = dts % 4; 
        if(mod == 1 || mod == 2) ret ^= b;
        else if(mod == 3) ret ^= 2; 
    
        printf("%lld\n", ret); 
    }
    
    return 0; 
    

    }