<p>There is only one character <code>&#39;A&#39;</code> on the screen of a notepad. You can perform one of two operations on this notepad for each step:</p>

<ul>
	<li>Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).</li>
	<li>Paste: You can paste the characters which are copied last time.</li>
</ul>

<p>Given an integer <code>n</code>, return <em>the minimum number of operations to get the character</em> <code>&#39;A&#39;</code> <em>exactly</em> <code>n</code> <em>times on the screen</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> Initially, we have one character &#39;A&#39;.
In step 1, we use Copy All operation.
In step 2, we use Paste operation to get &#39;AA&#39;.
In step 3, we use Paste operation to get &#39;AAA&#39;.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 1000</code></li>
</ul>

class Solution:
    def minSteps(self, n: int) -> int:
        # return self.recursive(n)
        # return self.recursive_with_memo(n)
        # return self.dp_top_down(n)
        # return self.dp_bottom_up(n)
        # return self.prime_factor(n)
        # return self.top(n)
        # return self.recursive_p(n)
        return self.recursive_with_memo_p(n)
        # return self.dp_top_down_p(n)
        # return self.dp_bottom_up_p(n)
        # return self.prime_factor_p(n)
        # return self.top_p(n)
    
    def top_p(self, n):
        if n == 1: return 0
        ops, curr, copy = 1, 1, 1
        while curr < n:
            if n % curr == 0 and curr != copy:
                copy = curr
            else:
                curr += copy
            ops += 1
        return ops
    
    def prime_factor_p(self, n):
        if n == 1: return 0
        ops, d = 0, 2
        while n > 1:
            while n % d == 0:
                n //= d
                ops += d
            d += 1
        return ops
    
    def dp_bottom_up_p(self, n):
        dp = [1000] * (n + 1)
        dp[1] = 0
        for i in range(2, n + 1):
            for j in range(1, i // 2 + 1):
                if i % j == 0:
                    dp[i] = min(dp[i], dp[j] + 1 + ((i -j) // j))
        return dp[n]

    def dp_top_down_p(self, n):
        if n == 1: return 0
        dp = [[0] * (n + 1) for _ in range(n + 1)]
        def _dfs(curr, copy):
            if curr == n: return 0
            if curr > n: return float(inf)
            if dp[curr][copy]: return dp[curr][copy]
            ops = float(inf)
            ops = min(ops, 2 + _dfs(curr * 2, curr))
            ops = min(ops, 1 + _dfs(curr + copy, copy))
            dp[curr][copy] = ops
            return ops
        return 1 + _dfs(1, 1)
    
    def recursive_with_memo_p(self, n):
        if n == 1: return 0
        memo = {}
        def _dfs(curr, copy):
            if curr == n: return 0
            if curr > n: return float(inf)
            if (curr, copy) in memo: return memo[(curr, copy)]
            ops = float(inf)
            ops = min(ops, 2 + _dfs(curr * 2, curr))
            ops = min(ops, 1 + _dfs(curr + copy, copy))
            memo[(curr, copy)] = ops
            return ops
        return 1 + _dfs(1, 1)
    
    def recursive_p(self, n):
        if n == 1: return 0
        @cache
        def _dfs(curr, copy):
            if curr == n: return 0
            if curr > n: return float(inf)
            ops = float(inf)
            ops = min(ops, 2 + _dfs(curr * 2, curr))
            ops = min(ops, 1 + _dfs(curr + copy, copy))
            return ops
        return 1 + _dfs(1, 1)

    def top(self, n):
        if n == 1: return 0
        curr, copy, operations = 1, 1, 1
        while curr < n:
            if n % curr == 0 and curr != copy:
                copy = curr
            else:
                curr += copy
            operations += 1
        return operations
    
    def prime_factor(self, n):
        ans = 0
        d = 2
        while n > 1:
            while n % d == 0:
                ans += d
                n //= d
            d += 1
        return ans                                                  
    
    def dp_bottom_up(self, n):
        dp = [1000] * (n + 1)
        dp[1] = 0
        for i in range(2, n + 1):
            for j in range(1, i // 2 + 1):
                if i % j == 0:
                    dp[i] = min(dp[i], dp[j] + i // j)
        return dp[n]
    
    def dp_top_down(self, n):
        if n == 1: return 0
        dp = [[0] * (n + 1) for _ in range(n + 1)]
        def _recursive(curr, copy):
            if curr == n: return 0
            if curr > n: return float(inf)
            if dp[curr][copy]: return dp[curr][copy]
            res = float(inf)
            res = min(res, 2 + _recursive(curr * 2, curr))
            res = min(res, 1 + _recursive(curr + copy, copy))
            dp[curr][copy] = res
            return res
        return 1 + _recursive(1, 1)
    
    def recursive_with_memo(self, n):
        if n == 1: return 0
        memo = {}
        def _recursive(curr, copy):
            if curr == n: return 0
            if curr > n: return float(inf)
            if (curr, copy) in memo: return memo[(curr, copy)]
            res = float(inf)
            res = min(res, 2 + _recursive(curr * 2, curr))
            res = min(res, 1 + _recursive(curr + copy, copy))
            memo[(curr, copy)] = res
            return res
        return 1 + _recursive(1, 1)
    
    def recursive(self, n):
        if n == 1: return 0
        @cache
        def _recursive(curr, copy):
            # print(curr)
            if curr == n: return 0
            if curr > n: return float(inf)
            res = float(inf)
            res = min(res, 2 + _recursive(2 * curr, curr))
            res = min(res, 1 + _recursive(curr + copy, copy))
            return res
        return 1 + _recursive(1, 1)
26446