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
function power ( x , y , mod ) { var res = 1 ; while ( y != 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; x = ( x * x ) % mod ; y = ( y >> 1 ) ; } return parseInt ( res % mod ) ; } function ncr ( n , r , mod ) { var res = 1 ; for ( var i = 1 ; i <= r ; i += 1 ) { res = ( res * ( n - i + 1 ) ) % mod ; var inv = power ( i , mod - 2 , mod ) ; res = ( res * inv ) % mod ; } return parseInt ( res % mod ) ; } function NoOfChords ( A ) { var mod = parseInt ( 7 ) ; var ans = ncr ( 2 * A , A , mod ) ; var inv = power ( A + 1 , mod - 2 , mod ) ; ans = ( ans * inv ) % mod ; return parseInt ( ans % mod ) ; } var N = 2 ; document . write ( NoOfChords ( N ) ) ;