Number of relations that are neither Reflexive nor Irreflexive on a Set | Java 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
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int mod = 1000000007 ; static int power ( int x , int y ) { int res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } static void countRelations ( int N ) { System . out . print ( ( power ( 2 , N ) - 2 ) * power ( 2 , N * N - N ) ) ; } public static void main ( String [ ] args ) { int N = 2 ; countRelations ( N ) ; } }