Find the minimum number of steps to reach M from N | Function to find a minimum number of steps to reach M from N ; Continue till m is greater than n ; If m is odd ; add one ; divide m by 2 ; Return the required answer ; Driver code
< ? php function Minsteps ( $ n , $ m ) { $ ans = 0 ; while ( $ m > $ n ) { if ( $ m % 2 != 0 ) { $ m ++ ; $ ans ++ ; } $ m /= 2 ; $ ans ++ ; } return $ ans + $ n - $ m ; } $ n = 4 ; $ m = 6 ; echo ( Minsteps ( $ n , $ m ) ) ; ? >