Input: N = 4, arr[] = {2, 6, 1, 5}
Output: B[] = {0, 6, 3, 6}
Explanation: Since, prefix array is prefixXor[] = {2, 4, 5, 0}, (2 ^ 0) + (4 ^ 6) + (5 ^ 3) + (0^6) = 2 + 2 + 6 + 6 = 16, which is even and divisible by 8.
Input: N = 6, arr[] = {2, 5, 3, 4, 6, 1}
Output: B[] = {0, 5, 1, 5, 5, 4}
Explanation: Since prefix, the array is prefixXor[]={2, 7, 4, 0, 6, 7}, So, (2 ^ 0) + (7 ^ 5) + (4 ^ 1) + (0 ^ 5) + (6 ^ 5) + (7 ^ 4) = 2 + 2 + 5 + 5 + 3 + 3 = 20, which is even and divisible by 10.
Let's first analyze the question. The given sum should be even and should be divisible by the first N/2 elements. So more formally it means :
if array arr[] = {a, b, c, d}, then its prefix xor is Prefix_xor[]=[a, a^b, a^b^c, a^b^c^d}
Let assume array B[] = {x, y, z, w} then S= (x^a) + (y^(a^b)) + (z^(a^b^c)) + ( w^(a^b^c^d)). So according to the question:
So on combining we get S % (2*(a + b)) == 0