title: Cut rectangle in minimum number of squares
body: <p>I'm trying to solve the following problem:</p>
  
  <blockquote>
    <p>A rectangular paper sheet of M*N is to be cut down into squares such that:</p>
    
    <ol>
    <li>The paper is cut along a line that is parallel to one of the sides of the paper.</li>
    <li>The paper is cut such that the resultant dimensions are always integers.</li>
    </ol>
    
    <p>The process stops when the paper can't be cut any further.</p>
    
    <p>What is the minimum number of paper pieces cut such that all are squares?</p>
    
    <p>Limits: 1 &lt;= N &lt;= 100 and 1 &lt;= M &lt;= 100.</p>
    
    <p>Example: Let N=1 and M=2, then answer is 2 as the minimum number of squares that can be cut is 2 (the paper is cut horizontally along the smaller side in the middle).</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>cin &gt;&gt; n &gt;&gt; m;
  
  int N = min(n,m);
  int M = max(n,m);
  int ans = 0;
  
  while (N != M) {
      ans++;
      int x = M - N;
      int y = N;
      M = max(x, y);
      N = min(x, y);
  }
  
  if (N == M &amp;&amp; M != 0)
     ans++;
  </code></pre>
  
  <p>But I am not getting what's wrong with this approach as it's giving me a wrong answer.</p>