You are viewing a single comment's thread. Return to all comments →
Here is my solution in Java
static long xorSequence(long l, long r) { long lsum = getXorSumAt(l-1); long rsum = getXorSumAt(r); return lsum ^ rsum; } static long getXorSumAt(long i) { long rem = i % 8; if (rem == 0 || rem == 1) return i; if (rem == 2 || rem == 3) return 2; if (rem == 4 || rem == 5) return i + 2; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Xor-sequence
You are viewing a single comment's thread. Return to all comments →
Here is my solution in Java