Minimum XOR of at most K elements in range [ L , R ] | Function for K = 2 ; Function for K = 2 ; Function for K = 2 ; Function to calculate the minimum XOR of at most K elements in [ L , R ] ; Driver code ; Input ; Function call
def func2 ( L , R , K ) : NEW_LINE INDENT if ( R - L >= 2 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return min ( L , L ^ R ) NEW_LINE DEDENT def func3 ( L , R , K ) : NEW_LINE INDENT if ( ( R ^ L ) > L and ( R ^ L ) < R ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return func2 ( L , R , K ) NEW_LINE DEDENT def func4 ( L , R , K ) : NEW_LINE INDENT if ( R - L >= 4 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT minval = L ^ ( L + 1 ) ^ ( L + 2 ) ^ ( L + 3 ) NEW_LINE return min ( minval , func3 ( L , R , K ) ) NEW_LINE DEDENT def minimumXor ( L , R , K ) : NEW_LINE INDENT if ( K > 4 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif ( K == 4 ) : NEW_LINE INDENT return func4 ( L , R , K ) NEW_LINE DEDENT elif ( K == 3 ) : NEW_LINE INDENT return func3 ( L , R , K ) NEW_LINE DEDENT elif ( K == 2 ) : NEW_LINE INDENT return func2 ( L , R , K ) NEW_LINE DEDENT else : NEW_LINE INDENT return L NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L , R , K = 1 , 3 , 3 NEW_LINE print ( minimumXor ( L , R , K ) ) NEW_LINE DEDENT