Count of N | JavaScript Program to implement the above approach ; Function to find the count of odd and even integers having N bits and K set bits ; Find the count of even integers ; Find the count of odd integers ; Print the total count ; Driver code
function factorial ( n ) { let ans = 1 ; while ( n >= 1 ) { ans *= n ; n -- ; } return ans ; } function Binary_Num ( n , k ) { let num_even , num_odd ; if ( n - k - 1 >= 0 && k - 1 >= 0 ) { num_even = Math . floor ( factorial ( n - 2 ) / ( factorial ( k - 1 ) * factorial ( n - k - 1 ) ) ) ; } else { num_even = 0 ; } if ( k - 2 >= 0 ) { num_odd = Math . floor ( factorial ( n - 2 ) / ( factorial ( k - 2 ) * factorial ( n - k ) ) ) ; } else { num_odd = 0 ; } document . write ( num_even + " " + num_odd + " " ) ; } let N = 9 , K = 6 ; Binary_Num ( N , K ) ;