<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>

struct hash_pair {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;  
    }
};
class Solution {
public:
    int findMinSteps(int i, int j, int n, int stepssoFar,unordered_map<pair<int,int>,int,hash_pair>& dp){
       // cout << i <<" "<< j<<endl; 
        if(i == n) return 0;
        if(i > n || stepssoFar > n) return INT_MAX;
        if(dp.find({i,j}) != dp.end()) return dp[{i,j}];
        int val1 = INT_MAX;
        if(i != j){
           val1 = findMinSteps(i,i,n,stepssoFar + 1,dp);
        }
        int val2 = INT_MAX;
        if(j != 0){
           val2 = findMinSteps(i+j,j,n,stepssoFar + 1,dp);
        }
        int retVal = min(val1,val2);
        if(retVal == INT_MAX) return INT_MAX;
        dp[{i,j}] = retVal + 1;
        return retVal + 1;
    }
    int minSteps(int n) {
        unordered_map<pair<int,int>,int,hash_pair> dp;
        return findMinSteps(1,0,n,0,dp);
    }
};
19295