Count of N | Java 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
import java . io . * ; class GFG { static long factorial ( int n ) { long ans = 1 ; while ( n >= 1 ) { ans *= n ; n -- ; } return ans ; } static void Binary_Num ( int n , int k ) { 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 ; } System . out . println ( num_even + " ▁ " + num_odd ) ; } public static void main ( String [ ] args ) { int N = 9 , K = 6 ; Binary_Num ( N , K ) ; } }