Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

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 ≤ 22 is the position a LOSS for the player to move?

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

Correct answer: C. 7

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic