Number of Relations that are both Irreflexive and Antisymmetric on a Set | Python 3 program for the above approach ; Function to calculate x ^ y % mod in O ( log y ) ; Stores the result of x ^ y ; Update x if it exceeds mod ; If y is odd , then multiply x with result ; Divide y by 2 ; Update the value of x ; Return the value of x ^ y ; Function to count relations that are irreflexive and antisymmetric in a set consisting of N elements ; Return the resultant count ; Driver Code
mod = 1000000007 NEW_LINE def power ( x , y ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % mod NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % mod NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % mod NEW_LINE DEDENT return res NEW_LINE DEDENT def numberOfRelations ( N ) : NEW_LINE INDENT return power ( 3 , ( N * N - N ) // 2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 2 NEW_LINE print ( numberOfRelations ( N ) ) NEW_LINE DEDENT