https://codeforces.com/gym/102832/problem/K
Once there was a lovely ragdoll cat, named Little Zara, who liked trees and math. One day she met the doge Adam. Adam had just planted some trees each consisting of only one node. The nodes were numbered from 11 to nn, and the ii-th node was assigned a value aiai. Adam liked pairing tree nodes, but he disliked some node pairs. A pair of nodes (i,j)(i,j) was considered bad if ii and jj were in the same tree and gcd(ai,aj)=ai⊕ajgcd(ai,aj)=ai⊕aj, where gcd(x,y)gcd(x,y) denotes the greatest common divisor (GCD) of integers xx and yy, and ⊕⊕ denotes the bitwise XOR operation. Adam wondered how many bad pairs there were in his forest.
Zara was good at solving problems about trees and math, so she could answer Adam's question in a short time. However, Adam was so naughty a dog that he would repeatedly change the forest slightly and ask Zara his