Subtraction Game Oracle — Solution & Editorial
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|)
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|)