Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

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

  1. A. 18
  2. B. 11
  3. C. 3
  4. D. 10

Correct answer: D. 10

Mark positions from 0 upward: the losing piles are 1, 2, 9, 10, 11, 18, 19, 20, 27, 28 (pattern p mod 9 ∈ {0, 1, 2}), so 10. Counting winners gives 18, including pile 0 gives 11, and treating only multiples of 9 as losing gives 3.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic