#include using namespace std; class UnionFind{ public: vector par,siz; vector have2,have3; void make(int N){ par.resize(N,-1); siz.resize(N,1); have2.resize(N); have3.resize(N); } int root(int x){ if(par.at(x) == -1) return x; else return par.at(x) = root(par.at(x)); } void unite(int u, int v){ u = root(u),v = root(v); if(u == v) return; if(siz.at(u) < siz.at(v)) swap(u,v); par.at(v) = u; siz.at(u) += siz.at(v); have2.at(u) = (have2.at(u)||have2.at(v)); have3.at(u) = (have3.at(u)||have3.at(v)); } bool issame(int u, int v){ if(root(u) == root(v)) return true; else return false; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int Need = 200000; vector>> Pf(Need+1); vector prime(Need+1,true); prime.at(0) = false; prime.at(1) = false; for(int i=2; i<=Need; i++){ if(!prime.at(i)) continue; Pf.at(i) = {{i,1}}; for(int k=i+i; k<=Need; k+=i){ prime.at(k) = false; int f = 0,k2 = k; while(k2%i == 0) f++,k2 /= i; Pf.at(k).push_back({i,f}); } } int N; cin >> N; UnionFind Z; Z.make(N); vector> fac(Need); for(int i=0; i> a; for(auto[p,e] : Pf.at(a)) fac.at(p).push_back(i); if(a%2 == 0) Z.have2.at(i) = true; if(a%3 == 0) Z.have3.at(i) = true; } int group = N; for(int i=0; i leader; for(int i=0; i= 3){ bool two = false; for(auto pos : leader) if(Z.have2.at(pos)) two = true; answer = 2*group; if(two) answer -= 2; } cout << answer << endl; }