2 Keys Keyboard
There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:
Copy All: You can copy all the characters present on the screen; a partial copy is not allowed.Paste: You can paste the characters which were copied last time.
Given an integer n, return the minimum number of operations needed to get the character 'A' exactly n times on the screen.
Example 1
Input
n = 3Output
3Starting with one
'A', copy all once and paste twice to get exactly three 'A' characters in 3 operations.Example 2
Input
n = 1Output
0The screen already has exactly one
'A', so no operations are needed.Constraints
- 1 <= n <= 1000