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 {1, 2, 4} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 24 is the position a LOSS for the player to move?

  1. A. 8
  2. B. 16
  3. C. 9
  4. D. 12

Correct answer: A. 8

Mark positions from 0 upward: with moves {1, 2, 4} the losing piles are exactly the multiples of 3 (3, 6, ..., 24), so 8. Counting winners gives 16, including pile 0 gives 9, and assuming every even pile loses gives 12.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic