Count even and odd Bitwise XORs of consecutive numbers in a range [ L , R ] starting from L | Print count of even and odd numbers of XOR value from L to R ; Store the number of elements between L and R ; Count of even XOR values ; If L is odd and range % 4 = 3 ; Increment even by 1 ; If L is even and range % 4 != 0 ; Increment even by 1 ; Print the answer ; Driver Code
function countEvenOdd ( L , R ) { let range = R - L + 1 ; let even = parseInt ( range / 4 ) * 2 ; if ( ( L & 1 ) && ( range % 4 == 3 ) ) { even ++ ; } else if ( ! ( L & 1 ) && ( range % 4 ) ) { even ++ ; } document . write ( " " + even + " " + ( range - even ) ) ; } let L = 2 , R = 7 ; countEvenOdd ( L , R ) ;