Bounded Nim — Solution & Editorial
Each pile is a subtraction game with Grundy value (pile mod (K+1)). XOR the Grundy values: non-zero means the first player wins (Sprague–Grundy).
Complexity: O(N)
Each pile is a subtraction game with Grundy value (pile mod (K+1)). XOR the Grundy values: non-zero means the first player wins (Sprague–Grundy).
Complexity: O(N)