Count of N | Python 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 math NEW_LINE def Binary_Num ( N , K ) : NEW_LINE INDENT if N - K - 1 >= 0 and K - 1 >= 0 : NEW_LINE INDENT num_even = math . factorial ( N - 2 ) / ( math . factorial ( K - 1 ) * math . factorial ( N - K - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT num_even = 0 NEW_LINE DEDENT if K - 2 >= 0 : NEW_LINE INDENT num_odd = math . factorial ( N - 2 ) / ( math . factorial ( K - 2 ) * math . factorial ( N - K ) ) NEW_LINE DEDENT else : NEW_LINE INDENT num_odd = 0 NEW_LINE DEDENT print ( int ( num_even ) , int ( num_odd ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 9 NEW_LINE K = 6 NEW_LINE Binary_Num ( N , K ) NEW_LINE DEDENT