Count pairs from a given range having equal Bitwise OR and XOR values | Java 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
import java . util . * ; class GFG { static final int MOD = 1000000007 ; static int power ( int x , int y ) { int res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % MOD ; y = y >> 1 ; x = ( x * x ) % MOD ; } return res ; } static void countPairs ( int N ) { System . out . print ( power ( 3 , N ) ) ; } public static void main ( String [ ] args ) { int N = 10 ; countPairs ( N ) ; } }