Number of relations that are neither Reflexive nor Irreflexive on a Set | Javascript program for the above approach ; Function to calculate x ^ y modulo 10 ^ 9 + 7 in O ( log y ) ; Stores the result of ( x ^ y ) ; Update x , if it exceeds mod ; If x is divisible by mod ; If y is odd , then multiply x with res ; Divide y by 2 ; Update the value of x ; Return the value of x ^ y ; Function to count the number of relations that are neither reflexive nor irreflexive ; Return the resultant count ; Driver Code
var mod = 1000000007 ; function power ( x , y ) { var res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y % 2 != 0 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } function countRelations ( N ) { document . write ( ( power ( 2 , N ) - 2 ) * power ( 2 , ( N * N ) - N ) ) ; } var N = 2 ; countRelations ( N ) ;