Count even and odd Bitwise XORs of consecutive numbers in a range [ L , R ] starting from L | Prcount 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 ; Prthe answer ; Driver Code
def countEvenOdd ( L , R ) : NEW_LINE INDENT range = R - L + 1 ; NEW_LINE even = ( range // 4 ) * 2 ; NEW_LINE if ( ( L & 1 ) != 0 and ( range % 4 == 3 ) ) : NEW_LINE INDENT even += 1 ; NEW_LINE DEDENT elif ( ( L & 1 ) == 0 and ( range % 4 != 0 ) ) : NEW_LINE INDENT even += 1 ; NEW_LINE DEDENT print ( " Even ▁ = ▁ " , even , " , ▁ Odd ▁ = ▁ " , ( range - even ) ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L = 2 ; R = 7 ; NEW_LINE countEvenOdd ( L , R ) ; NEW_LINE DEDENT