text: Check whether it is possible to convert A into B | C ++ implementation of the approach ; Function that returns true if A can be converted to B with the given operations ; If the current number ends with 1 ; If the current number is divisible by 2 ; If above two conditions fail ; If it is possible to convert A to B ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; bool canConvert ( int a , int b ) { while ( b > a ) { if ( b % 10 == 1 ) { b /= 10 ; continue ; } if ( b % 2 == 0 ) { b /= 2 ; continue ; } return false ; } if ( b == a ) return true ; return false ; } int main ( ) { int A = 2 , B = 82 ; if ( canConvert ( A , B ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }