XOR of pairwise sum of every unordered pairs in an array
问题 Question Description : Given an array arr[] of length N, the task is to find the XOR of pairwise sum of every possible unordered pairs of the array. I solved this question using the method described in this post. My Code : int xorAllSum(int a[], int n) { int curr, prev = 0; int ans = 0; for (int k = 0; k < 32; k++) { int o = 0, z = 0; for (int i = 0; i < n; i++) { if (a[i] & (1 << k)) { o++; } else { z++; } } curr = o * z + prev; if (curr & 1) { ans = ans | (1 << k); } prev = o * (o - 1) / 2;