constexprint N = 1e7; std::vector<int> primes; int minp[N + 1]; // minp[i] = min prime factor of i int num[N + 1]; // num[i] = number of prime factors of i voidinit(){ for (int i = 2; i <= N; i++) { if (!minp[i]) { minp[i] = i; primes.push_back(i); num[i] = 1; } for (auto p : primes) { if (i * p > N) break; minp[i * p] = p; num[i * p] = num[i] + 1; if (i % p == 0) break; } } } boolis_prime(int x){ if (x <= 1) { returnfalse; } return minp[x] == x; } std::vector<int> get_facts(int x){ std::vector<int> facts; int t = x; while (t > 1) { if (facts.empty() || facts.back() != minp[t]) { facts.push_back(minp[t]); } t /= minp[t]; } return facts; }