title: How this algorithm actually works and thought process behind it?
body: <p>I came across this question as follows:</p>
  <p>There are three integers a, b, c given in input. You have to convert the number a to b by performing the given operations:</p>
  <ol>
  <li>Multiply a by c</li>
  <li>Decrease a by 2.</li>
  <li>Decrease a by 1.</li>
  </ol>
  <p>You have to perform the above operations to convert the integer from a to b and find the minimum steps.
  Note: You can perform the operations in any order.</p>
  <p>I found this solution:</p>
  <pre><code>def rec(a,b,c):
  
      if a&gt;=b:
          return ((a-b)//2+(a-b)%2)
  
      if b%c==0:
          return (1+rec(a,b//c,c))
  
      else:
          x=(b//c+1)*c;
          return ((x-b)//2+(x-b)%2+rec(a,x,c))
  
  
  a,b,c=map(int,input().split())
  print(rec(a,b,c))
  </code></pre>
  <p>The first condition check is easily understandable that if (a&gt;=b) then we decrement a in steps of 2 until we reach b and if there is a remainder &quot;1&quot; we add it to the steps to compute the final output.</p>
  <p>In second and third condition checks it successfully performs the required operation using the concept of recursion, but why recursion is used? Is it possible to do it without recursion? What is the use of x in third condition?</p>