#include<iostream> #include<cstdio> #include<unordered_map> #include<vector> #define maxn 300010 #define ll long long usingnamespacestd;
intgcd(int a, int b){ return b == 0 ? a : gcd(b, a % b); }
int n, m;
int v[maxn];
vector<int> a[maxn]; voidinit(int n){ for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) { int k = i ^ j; if (gcd(k, j) == i) a[j].push_back(k); } }
int fa[maxn]; voidinit_fa(int n){ for (int i = 1; i <= n; ++i) fa[i] = i; }
intfind(int x){ return x == fa[x] ? x : fa[x] = find(fa[x]); }
unordered_map<int, int> mp[maxn];
ll ans; inlinevoidsolve_1(){ int x, y; cin >> x >> y; v[x] = y; mp[x][v[x]] = 1; }
inlinevoidsolve_2(){ int x, y, fx, fy; cin >> x >> y; if ((fx = find(x)) == (fy = find(y))) return; if (mp[fx].size() < mp[fy].size()) swap(fx, fy); for (auto u : mp[fy]) for (auto v : a[u.first]) if (mp[fx].find(v) != mp[fx].end()) ans += (ll) mp[fx][v] * u.second; for (auto u : mp[fy]) mp[fx][u.first] += u.second; fa[fy] = fx; }
inlinevoidsolve_3(){ int x, y, fx; cin >> x >> y; fx = find(x); for (auto u : a[v[x]]) if (mp[fx].find(u) != mp[fx].end()) ans -= mp[fx][u]; --mp[fx][v[x]]; v[x] = y; ++mp[fx][v[x]]; for (auto u : a[v[x]]) if (mp[fx].find(u) != mp[fx].end()) ans += mp[fx][u]; }