fork(6) download
  1. #include <set>
  2. #include <vector>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector<int> primes = { 2, 3, 5, 7, 11, 17, 23 };
  8. int num = 100005917;
  9. // initialize bestCandidate as a power of some prime greater than num
  10. int bestCandidate = 1;
  11. while (bestCandidate < num) bestCandidate *= primes[0];
  12. set<int> s;
  13. s.insert(1);
  14. while (s.size()) {
  15. int current = *s.begin();
  16. s.erase(s.begin());
  17. for (auto p : primes) { // generate new candidates
  18. int newCandidate = current * p;
  19. if (newCandidate < num) {
  20. // new lower candidates should be stored.
  21. if (s.find(newCandidate) == s.end())
  22. s.insert(newCandidate);
  23. }
  24. else {
  25. if (newCandidate < bestCandidate) bestCandidate = newCandidate;
  26. break; // further iterations will generate only larger numbers
  27. }
  28. }
  29. }
  30. cout << bestCandidate;
  31. }
Success #stdin #stdout 0.02s 3724KB
stdin
Standard input is empty
stdout
100012671