Count pairs from a given range having equal Bitwise OR and XOR values | Javascript program for the above approach ; Function to calculate ( x ^ y ) % MOD ; Initialize result ; Update x if it is more than or equal to MOD ; If y is odd , multiply x with result ; y must be even now y = y / 2 ; Return ( x ^ y ) % MOD ; Function to count total pairs ; The upper bound is 2 ^ N ; Stores the count of pairs ; Generate all possible pairs ; Find XOR of both integers ; Find OR of both integers ; If both are equal ; Increment count ; Print count % MOD ; Driver Code ; Function Call
MOD = 1000000007 ; function power ( x , y ) { var res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % MOD ; y = y >> 1 ; x = ( x * x ) % MOD ; } return res ; } function countPairs ( N ) { var high = power ( 2 , N ) ; var count = 0 ; for ( i = 0 ; i < high ; i ++ ) { for ( j = 0 ; j < high ; j ++ ) { var X = ( i ^ j ) ; var Y = ( i j ) ; if ( X == Y ) { count ++ ; } } } document . write ( count % MOD ) ; } var N = 10 ; countPairs ( N ) ;