# Print all distinct even and odd prefix Bitwise XORs of first N natural numbers

Print all distinct even and odd prefix Bitwise XORs of first N natural numbersGiven a positive integer N, the task is to print all the distinct even and odd values of prefix Bitwise XORs of first N natural numbers.Examples:Input: N = 6Output:Even: 0 4Odd: 1 3 7Explanation:The prefix Bitwise XOR of the first 6 natural number si {1, 3, 0, 4, 1, 7}.Even prefix Bitwise XORs are 0, 4.Odd prefix Bitwise XORs are 1, 3, 7.Input: N = 9Output:Even: 0 4 8Odd: 1 3 7Approach: The given problem can be solved based on the below observations:If the value of N modulo 4 is 0, then the value of Bitwise XOR of the first N natural numbers is N.If the value of N modulo 4 is 1, then the value of Bitwise XOR of the first N natural numbers is 1.If the value of N modulo 4 is 2, then the value of Bitwise XOR of the first N natural numbers is (N + 1).If the value of N modulo 4 is 3, then the value of Bitwise XOR of the first N natural numbers is 0.Therefore, from the above principle, it can be said that Bitwise XOR as even numbers will always come as 0 or multiples of 4, and Bitwise XOR as odd numbers will always come as 1 or 1 less than multiples of 4.Below is the implementation of the above approach.C++  #include using namespace std;  void evenOddBitwiseXOR(int N){      cout