fork(2) download
  1. #include <list>
  2. #include <vector>
  3. #include <iostream>
  4. #include <limits.h>
  5. using namespace std;
  6.  
  7. int main() {
  8. vector<int> primes = { 2, 3, 5, 7, 11, 17, 23 };
  9. int num = 100005917;
  10. int bestCandidate = INT_MAX;
  11. list<pair<int, int> > ls;
  12. ls.push_back(make_pair(1, 0));
  13. while (ls.size()) {
  14. long long currentProd = ls.front().first;
  15. int primesUsed = ls.front().second;
  16. ls.pop_front();
  17. int currentPrime = primes[primesUsed];
  18. while (currentProd < num) {
  19. if(primesUsed < primes.size() - 1)
  20. ls.push_back(make_pair(currentProd, primesUsed + 1));
  21. currentProd *= currentPrime;
  22. }
  23. bestCandidate = min((long long)bestCandidate, currentProd);
  24. }
  25. cout << bestCandidate;
  26. }
Success #stdin #stdout 0.37s 3676KB
stdin
Standard input is empty
stdout
100012671