Learn / Library / Brainteasers
A counter with buttons
A counter shows . Each press of button A multiplies the shown number by , and each press of button B adds to it. What is the fewest number of presses that makes the counter show exactly ?
Checking an answer needs JavaScript. The hint and the solution open without it.
Hint
Work backwards from : when can the last press have been a multiplication?
Solution
- Backwards, a press of A divides by , which is possible only for a multiple of , and a press of B subtracts .
- From , subtract to , divide to and , subtract to and , and divide to and .
- The subtractions are forced, since , and are not multiples of , and dividing whenever possible keeps the route shortest.
- So the fewest number of presses is .
Answer: