Count pairs from a given range having equal Bitwise OR and XOR values | Python program for the above approach ; Function to find the value of ( 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 , then update y / 2 ; Return ( x ^ y ) % MOD ; Function to count total pairs ; Finding 3 ^ N % 10 ^ 9 + 7 ; Driver Code ; Function Call
MOD = 1000000007 ; NEW_LINE def power ( x , y ) : NEW_LINE INDENT res = 1 ; NEW_LINE x = x % MOD ; NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y % 2 == 1 ) : NEW_LINE INDENT res = ( res * x ) % MOD ; NEW_LINE DEDENT y = y >> 1 ; NEW_LINE x = ( x * x ) % MOD ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT def countPairs ( N ) : NEW_LINE INDENT print ( power ( 3 , N ) ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 10 ; NEW_LINE countPairs ( N ) ; NEW_LINE DEDENT