Problems > Classic Nim > Editorial

Classic Nim — Solution & Editorial

Back to the Problem

The Sprague–Grundy classic: FIRST wins iff the XOR of all pile sizes is non-zero (a non-zero XOR always has a move to zero; zero XOR must move to non-zero).

Complexity: O(N)