Minimum value of N such that xor from 1 to N is equal to K | Function to find the value of N ; handling case for '0 ; handling case for '1 ; when number is completely divided by 4 then minimum ' x ' will be 'k ; when number divided by 4 gives 3 as remainder then minimum ' x ' will be 'k-1 ; else it is not possible to get k for any value of x ; let the given number be 7
def findN ( k ) : NEW_LINE ' NEW_LINE INDENT if ( k == 0 ) : NEW_LINE INDENT ans = 3 NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT if ( k == 1 ) : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT elif ( k % 4 == 0 ) : NEW_LINE INDENT ans = k NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT elif ( k % 4 == 3 ) : NEW_LINE INDENT ans = k - 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = - 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT k = 7 NEW_LINE res = findN ( k ) NEW_LINE if ( res == - 1 ) : NEW_LINE INDENT print ( " Not ▁ possible " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( res ) NEW_LINE DEDENT