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 ] ; Input ; Function call
function func2 ( L , R , K ) { if ( R - L >= 2 ) return 1 ; return Mat . min ( L , L ^ R ) ; } function func3 ( L , R , K ) { if ( ( R ^ L ) > L && ( R ^ L ) < R ) return 0 ; return func2 ( L , R , K ) ; } function func4 ( L , R , K ) { if ( R - L >= 4 ) return 0 ; var minval = L ^ ( L + 1 ) ^ ( L + 2 ) ^ ( L + 3 ) ; return Math . min ( minval , func3 ( L , R , K ) ) ; } function minimumXor ( L , R , K ) { if ( K > 4 ) return 0 ; else if ( K == 4 ) return func4 ( L , R , K ) ; else if ( K == 3 ) return func3 ( L , R , K ) ; else if ( K == 2 ) return func2 ( L , R , K ) ; else return L ; } var L = 1 , R = 3 , K = 3 ; document . write ( minimumXor ( L , R , K ) ) ;