Minimum number operations required to convert n to m | Set | PHP implementation of the above approach ; Function to find the minimum number of steps ; If n exceeds M ; If N reaches the target ; The minimum of both the states will be the answer ; Driver code
< ? php $ MAXN = 10000000 ; function minimumSteps ( $ n , $ m , $ a , $ b ) { global $ MAXN ; if ( $ n > $ m ) return $ MAXN ; if ( $ n == $ m ) return 0 ; return min ( 1 + minimumSteps ( $ n * $ a , $ m , $ a , $ b ) , 1 + minimumSteps ( $ n * $ b , $ m , $ a , $ b ) ) ; } $ n = 120 ; $ m = 51840 ; $ a = 2 ; $ b = 3 ; echo minimumSteps ( $ n , $ m , $ a , $ b ) ; ? >