Count ways to divide circle using N non | Function to calculate x ^ y % mod efficiently ; Initialize the answer ; If power is odd ; Update the answer ; Square the base and half the exponent ; Return the value ; Function to calculate ncr % mod efficiently ; Initialize the answer ; Calculate ncr in O ( r ) ; Multiply with the numerator factor ; Calculate the inverse of factor of denominator ; Multiply with inverse value ; Return answer value ; Function to return the number of non intersecting chords ; define mod value ; Value of C ( 2 n , n ) ; Modulo inverse of ( n + 1 ) ; Multiply with modulo inverse ; Return the answer ; Driver code ; Function call
def power ( x , y , mod ) : NEW_LINE INDENT res = 1 NEW_LINE while ( y ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % mod NEW_LINE DEDENT x = ( x * x ) % mod NEW_LINE y = ( y >> 1 ) NEW_LINE DEDENT return ( res % mod ) NEW_LINE DEDENT def ncr ( n , r , mod ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT res = ( res * ( n - i + 1 ) ) % mod NEW_LINE inv = power ( i , mod - 2 , mod ) NEW_LINE res = ( res * inv ) % mod NEW_LINE DEDENT return ( res % mod ) NEW_LINE DEDENT def NoOfChords ( A ) : NEW_LINE INDENT mod = 10 ** 9 + 7 NEW_LINE ans = ncr ( 2 * A , A , mod ) NEW_LINE inv = power ( A + 1 , mod - 2 , mod ) NEW_LINE ans = ( ans * inv ) % mod NEW_LINE return ( ans % mod ) NEW_LINE DEDENT N = 2 NEW_LINE print ( NoOfChords ( N ) ) NEW_LINE