Problem. A pile of stones; players alternately take stones; whoever takes the last stone wins. (The “21 game” is , in reverse form.)

Answer: the first player loses iff ; the winning move is to take stones.

bool bachetFirstWins(long long n, long long k) { return n % (k + 1) != 0; }    // take 1..k, last stone wins
VariantLosing positions
misère (taking the last stone loses)
allowed moves form a set compute win/lose by DP; the pattern is eventually periodic
several pilesGrundy value per pile, XOR them (Sprague–Grundy)