Finding XOR of all even numbers from n to m Problem : Given a range $[n,m]$, find the xor of all even numbers in this range. Constraints : $1 \le n \le m \le 10^{18}$
How do we solve this problem?
P.S. I asked this question at stackoverflow but that was not the appropriate place to ask this question. So I re-asked it here.

Something like this:
For bit $k$,
where $k=0$ is the 
units bit,
blocks of length
$2^{k+1}$
xor to zero,
since there are
$2^k$ with a $0$
and
$2^k$ with a $1$.
Therefore,
we can xor the $k$-th bit
from
$i=
n+\lfloor \frac{m-n}{2^{k+1}} \rfloor
$
to
$m$
to get that bit,
since the blocks of
length $2^{k+1}$
xor to zero.
Do this until
$2^{k} > m$.
