Problems > Subtraction Game Oracle > Editorial

Subtraction Game Oracle — Solution & Editorial

Back to the Problem

Compute Grundy numbers g[n] = mex{ g[n−s] : s in S, s ≤ n } up to the maximum query; g[n] ≠ 0 means the first player wins. (Grundy sequences become periodic, enabling huge n.)

Complexity: O(max n · |S|)