Count of N | C ++ program for 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long factorial ( int n ) { long long ans = 1 ; while ( n >= 1 ) { ans *= n ; n -- ; } return ans ; } void Binary_Num ( int n , int k ) { long long num_even , num_odd ; if ( n - k - 1 >= 0 && k - 1 >= 0 ) { num_even = factorial ( n - 2 ) / ( factorial ( k - 1 ) * factorial ( n - k - 1 ) ) ; } else { num_even = 0 ; } if ( k - 2 >= 0 ) { num_odd = factorial ( n - 2 ) / ( factorial ( k - 2 ) * factorial ( n - k ) ) ; } else { num_odd = 0 ; } cout << num_even << " ▁ " << num_odd << endl ; } int main ( ) { int N = 9 , K = 6 ; Binary_Num ( N , K ) ; return 0 ; }