Number of Asymmetric Relations on a set of N elements | Java program for the above approach ; Function to calculate x ^ y modulo ( 10 ^ 9 + 7 ) ; 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 result ; Divide y by 2 ; Update the value of x ; Return the final value of x ^ y ; Function to count the number of asymmetric relations in a set consisting of N elements ; Return the resultant count ; Driver code
import java . io . * ; class GFG { final static int mod = 1000000007 ; public static int power ( int x , int y ) { int res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } public static int asymmetricRelation ( int N ) { return power ( 3 , ( N * N - N ) / 2 ) ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . print ( asymmetricRelation ( N ) ) ; } }