Find N distinct numbers whose Bitwise XOR is equal to K | Function to find N integers having Bitwise XOR equal to K ; Base Cases ; Assign values to P and Q ; Stores Bitwise XOR of the first ( N - 3 ) elements ; Print the first N - 3 elements ; Calculate Bitwise XOR of first ( N - 3 ) elements ; Driver Code ; Function Call
def findArray ( N , K ) : NEW_LINE INDENT if ( N == 1 ) : NEW_LINE INDENT print ( K , end = " ▁ " ) NEW_LINE return NEW_LINE DEDENT if ( N == 2 ) : NEW_LINE INDENT print ( "0" , end = " ▁ " ) NEW_LINE print ( K , end = " ▁ " ) NEW_LINE return NEW_LINE DEDENT P = N - 2 NEW_LINE Q = N - 1 NEW_LINE VAL = 0 NEW_LINE for i in range ( 1 , N - 2 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE VAL ^= i NEW_LINE DEDENT if ( VAL == K ) : NEW_LINE INDENT print ( P , end = " ▁ " ) NEW_LINE print ( Q , end = " ▁ " ) NEW_LINE print ( P ^ Q , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "0" , end = " ▁ " ) NEW_LINE print ( P , end = " ▁ " ) NEW_LINE print ( P ^ K ^ VAL , end = " ▁ " ) NEW_LINE DEDENT DEDENT N = 4 NEW_LINE X = 6 NEW_LINE findArray ( N , X ) NEW_LINE