Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional

A pile holds p stones. In one move a player removes exactly s stones, where s is one of {4, 5, 6} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 18 is the position a LOSS for the player to move?

  1. A. 7
  2. B. 11
  3. C. 8
  4. D. 9

Correct answer: A. 7

Mark positions from 0 upward: p is losing exactly when no allowed s leads to a losing position. There are 7 losing piles in 1 to 18. Counting the winning ones instead gives 11, and including pile 0 gives 8.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic