First of all use descriptive variable names, such as start, target, and steps.
No, there isn't an easy way to do this, but there are straightforward ways.
First, you need to find the necessary change. Break down both start and target into factors of 2, factors of 3, and anything else. If this "anything" else" doesn't match, then you can't solve the problem at all.
For instance, look at your given problem: going from 9 to 4. Breaking down each number:
9 = 3*3 # no 2's, no other stuff
4 = 2*2 # no 3's, no other stuff
Since the "other" stuff matches (i.e. 1), you can make the transition. You need to remove 2 factors of 3, and add 2 factors of 2. That's 4 steps. From there, all you have to do is add pairs of *3/3 or *2/2 until you have 8 steps.
Let's try with changing 56 into 126:
56 = 2*2*2*7 # no 3's, other = 7
126 = 2*3*3*7 # other = 7
To make the transition, you need to remove two 2's and add two 3's. That's four steps; you adjust to the desired number as before.
There's your attack; can you code that?