Approach hintTry it first, then revealHide
Comparing every pair is quadratic. Treat each bit position separately: if c of the n numbers have the bit set, that position contributes c * (n - c) differing pairs.
Comparing every pair is quadratic. Treat each bit position separately: if c of the n numbers have the bit set, that position contributes c * (n - c) differing pairs.