Count pairs from a given range having equal Bitwise OR and XOR values | C ++ 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
#include <bits/stdc++.h> NEW_LINE #define MOD  1000000007 NEW_LINE using namespace std ; long long int power ( int x , int y ) { long long int res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % MOD ; y = y >> 1 ; x = ( x * x ) % MOD ; } return res ; } void countPairs ( int N ) { cout << power ( 3 , N ) ; } int main ( ) { int N = 10 ; countPairs ( N ) ; return 0 ; }