document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <vector>
  3. #include <inttypes.h>
  4. #include <cmath>
  5.  
  6. //compile on osx: clang -lstdc++ ./erato.cpp -o erato
  7. //compile on cygwin clang++ -lgmp -lstdc++ ./erato.cpp -o erato
  8.  
  9. //sieve and main omitted
  10.  
  11. uint64_t maximum_prime_product(uint64_t limit)
  12. {
  13.   std::vector<uint64_t> primes = primes_to(limit/2);
  14.   uint64_t i = 0;
  15.   uint64_t j = primes.size() - 1;
  16.   uint64_t max_product = 0;
  17.   while (i <= j)
  18.     {
  19.     while ((primes[i] * primes[j]) > limit)
  20.       {
  21.     j--;
  22.       }
  23.     if ((primes[i] * primes[j]) > max_product)
  24.       max_product = primes[i] * primes[j];
  25.     i++;    
  26.     }
  27.   return max_product;
  28. }
');