Skip to content

Instantly share code, notes, and snippets.

@wuqiangcpp
wuqiangcpp / nearest_good_num.cpp
Last active October 11, 2025 08:55
find nearest integer which only have selected prime factors
int nearest_upper_good_num(int num,const std::vector<int> & primes){
int bestCandidate = INT_MAX;
std::list<std::pair<int, int> > ls;
ls.push_back(std::make_pair(1, 0));
while (ls.size()) {
int currentProd = ls.front().first;
int primesUsed = ls.front().second;
ls.pop_front();
int currentPrime = primes[primesUsed];
while (currentProd < num) {