mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Updated problem 27 algorithm
This commit is contained in:
@@ -56,7 +56,7 @@ public:
|
||||
The greatest number of primes found is 70
|
||||
It was found with A = -61, B = 971
|
||||
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
|
||||
|
||||
@@ -42,7 +42,7 @@ std::string getBenchmarkResults(Problem* problem, double totalTime, unsigned int
|
||||
//Variables
|
||||
//Valid menu options
|
||||
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
|
||||
|
||||
@@ -43,8 +43,6 @@ void Problem27::solve(){
|
||||
//Start the timer
|
||||
timer.start();
|
||||
|
||||
primes = mee::getPrimes((int64_t)(12000));
|
||||
|
||||
//Start with the lowest possible A and check all possibilities after that
|
||||
for(int64_t a = -999;a <= 999;++a){
|
||||
//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
|
||||
int64_t n = 0;
|
||||
int64_t quadratic = (n * n) + (a * n) + b;
|
||||
while(mee::isFound(primes, quadratic)){
|
||||
while(mee::isPrime(quadratic)){
|
||||
++n;
|
||||
quadratic = (n * n) + (a * n) + b;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user