Problems > XOR of 1..N > Editorial

XOR of 1..N — Solution & Editorial

Back to the Problem

The prefix XOR is periodic with period 4: it equals N, 1, N+1, 0 for N ≡ 0, 1, 2, 3 (mod 4).

Complexity: O(1)