I'd like to ask the sum of triplets satisfying that its nim-sum is zero, i.e., $$\operatorname{sum}_3(n)=\sum_{0 \leq i,j,k \leq n, i \text{ xor } j \text{ xor } k=0} (i+j+k).$$
If just counting the number of triplets, there is a formula: $2^{2\lfloor log_2 n \rfloor}+3(n+1-2^{\lfloor log_2 n \rfloor})^2$.
My first try is to follow the same procedure: denote $n=2^b-1+c$ where $b=\lfloor log_2 n \rfloor$, then $\operatorname{sum}_3(n)=\operatorname{sum}_3(2^b-1+c)=\operatorname{sum}_3(2^b-1)+3 \cdot 2^b \cdot 2 \cdot c^2+\text{remain}$, where $\operatorname{sum}_3(2^b-1)=4^{b-1} \cdot (2^b-1) \cdot 6$. The $\text{remain}$ accounts for those "large" triplets after subtracting two $2^b$ from the biggest terms. But I get stuck when calculating the remaining part.
Edit: $\text{remain}=3\sum_{0\leq i,j \lt c}(i+j+(i \text{ xor } j))=3 \cdot c^2(c-1)+3 \sum_{0 \leq i,j \leq c-1} (i \text{ xor } j)$ which can be calculated in $O(\log(n))$.