Check if a pair of integers from two ranges exists such that their Bitwise XOR exceeds both the ranges | C ++ program for the above approach ; Function to check if there exists any pair ( P , Q ) whose Bitwise XOR is greater than the Bitwise XOR of X and Y ; Stores the Bitwise XOR of X & Y ; Traverse all possible pairs ; If a pair exists ; If a pair is found ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findWinner ( int X , int Y ) { int playerA = ( X ^ Y ) ; bool flag = false ; for ( int i = 1 ; i <= X ; i ++ ) { for ( int j = 1 ; j <= Y ; j ++ ) { int val = ( i ^ j ) ; if ( val > playerA ) { flag = true ; break ; } } if ( flag ) { break ; } } if ( flag ) { cout << " Yes " ; } else { cout << " No " ; } } int main ( ) { int A = 2 , B = 4 ; findWinner ( A , B ) ; return 0 ; }