You are given an array A containing N positive integers (1 <= A[i] <= 10^9)
Let F(i,j,k) = ( A[i] | A[j] ) & A[k]
| represents bitwise OR and & represents bitwise AND
The task is to determine the bitwise XOR of F(A,B,C) over all triplets (A,B,C) such that 1<= A,B,C <=N
for Example:
if N=2 and A=[1,4]
triplets will be:
- F(1,1,1) = 1
- F(1,1,2) = 0
- F(1,2,1) = 1
- F(1,2,2) = 4
- F(2,1,1) = 1
- F(2,1,2) = 4
- F(2,2,1) = 0
- F(2,2,2) = 4
Bitwise XOR of all = 1^0^1^4^1^4^0^4 = 5
so the answer is 5.
one more example:
if A=[14,9,19,18,17,11,12] answer=16
How to solve this question or how to proceed with such questions?
Code in javascript would be helpful, but other languages are also welcome.