The More Cats, the Better
InterviewTime limit1sMemory limit1024 MB
Given N, find the fewest creation or cloning spells that leave exactly N cats, where a cloning spell adds up to the current cat count.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Recursion, Math
- Solved
- No attempts yet
Problem
Magical girl Madoka loves cats so much that she has decided to raise cats at home using magic!
In each action, Madoka chooses one of the following spells and casts it. At the start, Madoka's house has no cats.
- Creation spell: Creates cat in Madoka's house.
- Cloning spell: Clones some or all of the cats in Madoka's house. That is, if there are currently cats in the house, Madoka can add between and cats to the house.
Madoka wants to use the spells above wisely so that the house has exactly cats in the minimum number of actions. Since Madoka finds calculating difficult, compute the minimum number of actions for her!
Input
The first line contains the desired number of cats () as an integer.
Output
On the first line, print the minimum number of actions needed to have exactly cats in Madoka's house.