text: Check if it is possible to reach ( X , Y ) from ( 1 , 1 ) by given steps | C ++ program for the above approach ; Function to find the gcd of two numbers ; Base case ; Recurse ; Function to print the answer ; GCD of X and Y ; If GCD is power of 2 ; Driver code ; Given X and Y ; Function call
code: #include <iostream> NEW_LINE using namespace std ; int gcd ( int a , int b ) { if ( a < b ) { int t = a ; a = b ; b = t ; } if ( a % b == 0 ) return b ; return gcd ( b , a % b ) ; } void printAnswer ( int x , int y ) { int val = gcd ( x , y ) ; if ( ( val & ( val - 1 ) ) == 0 ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int x = 4 ; int y = 7 ; printAnswer ( x , y ) ; return 0 ; }