Canadian Computing Competition: 2013 Stage 1, Senior #5
In the game of Factor Solitaire, you start with the number , and try to change it to some given target number by repeatedly using the following operation. In each step, if is your current number, you split it into two positive factors , of your choice such that . You then add to your current number to get your new current number. Doing this costs you points.
You continue doing this until your current number is , and you try to achieve this at the cost of a minimum total number of points.
For example, here is one way to get to :
- start with
- change to — cost so far is
- change to — cost so far is
- change to — cost so far is
- change to — cost so far is
- change to — done, total cost is .
In fact, this is the minimum possible total cost to get . You want to compute the minimum total cost for other target end numbers.
Input Specification
The input consists of a single integer . In at least half of the cases , in at least another quarter of the cases , and in the remaining cases .
Output Specification
Compute the minimum cost that gets you to .
Sample Input 1
15
Output for Sample Input 1
9
Sample Input 2
2013
Output for Sample Input 2
91
Explanation of Output for Sample Input 2
For example, start with , then get to , , , , , , , , , , , , , , and then .
Comments
Can the factors be decimal?
In comments of my solution, I sketch a proof that gives description to all possible sequences of moves that will achieve minimum cost and derives an algebraic identity satisfied by the cost function which suggests the considerably different algorithm that I implement.
hint! back is the way to go!!!