## CCC '13 S5 - Factor Solitaire

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem types
##### 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 .