All problems

Problem 954

2 Keys Keyboard

Medium · 20 pts · Math, Dynamic Programming

Problem

A notepad starts with a single character A. You may Copy All (copy everything currently on the screen) or Paste (append whatever was copied last). Find the minimum number of operations to get exactly N characters A on the screen. Getting from d to d × k characters costs one copy and k - 1 pastes, which is k operations, so the answer is the sum of the prime factors of N, counted with multiplicity.

Input

A single integer N.

Output

Print the minimum number of operations.

Constraints

1 <= N <= 10^6

Example input

3

Example output

3

Explanation

For N = 3: Copy All, Paste (AA), Paste (AAA). That takes 3 operations.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Maximum Length of Pair Chain Next: 4 Keys Keyboard