Updated problem 27 algorithm

This commit is contained in:
2020-10-30 16:18:59 -04:00
parent 0132ebebf3
commit 2d6279b31f
3 changed files with 3 additions and 5 deletions

View File

@@ -56,7 +56,7 @@ public:
The greatest number of primes found is 70 The greatest number of primes found is 70
It was found with A = -61, B = 971 It was found with A = -61, B = 971
The product of A and B is -59231 The product of A and B is -59231
It took an average of 2.176 seconds to run this problem over 100 iterations It took an average of 14.261 milliseconds to run this problem over 100 iterations
*/ */
#endif //PROBLEM27_HPP #endif //PROBLEM27_HPP

View File

@@ -42,7 +42,7 @@ std::string getBenchmarkResults(Problem* problem, double totalTime, unsigned int
//Variables //Variables
//Valid menu options //Valid menu options
enum BENCHMARK_OPTIONS {RUN_SPECIFIC = 1, RUN_ALL_SHORT, RUN_ALL, BENCHMARK_EXIT, BENCHMARK_SIZE}; enum BENCHMARK_OPTIONS {RUN_SPECIFIC = 1, RUN_ALL_SHORT, RUN_ALL, BENCHMARK_EXIT, BENCHMARK_SIZE};
std::vector<unsigned int> tooLong = {5, 15, 23, 24, 27, 29}; //The list of problems that take "too long" to run. (Over 1 second on my machine) std::vector<unsigned int> tooLong = {5, 15, 23, 24, 29}; //The list of problems that take "too long" to run. (Over 1 second on my machine)
//The driver function for the benchmark selection //The driver function for the benchmark selection

View File

@@ -43,8 +43,6 @@ void Problem27::solve(){
//Start the timer //Start the timer
timer.start(); timer.start();
primes = mee::getPrimes((int64_t)(12000));
//Start with the lowest possible A and check all possibilities after that //Start with the lowest possible A and check all possibilities after that
for(int64_t a = -999;a <= 999;++a){ for(int64_t a = -999;a <= 999;++a){
//Start with the lowest possible B and check all possibilities after that //Start with the lowest possible B and check all possibilities after that
@@ -52,7 +50,7 @@ void Problem27::solve(){
//Start with n=0 and check the formula to see how many primes you can get with concecutive n's //Start with n=0 and check the formula to see how many primes you can get with concecutive n's
int64_t n = 0; int64_t n = 0;
int64_t quadratic = (n * n) + (a * n) + b; int64_t quadratic = (n * n) + (a * n) + b;
while(mee::isFound(primes, quadratic)){ while(mee::isPrime(quadratic)){
++n; ++n;
quadratic = (n * n) + (a * n) + b; quadratic = (n * n) + (a * n) + b;
} }