Updated getNumPrimes to be more efficient

This commit is contained in:
2019-01-30 22:09:57 -05:00
parent cea62c9404
commit c77f9d71e0

View File

@@ -1,7 +1,7 @@
//myClasses/Algorithms.hpp
//Matthew Ellison
// Created: 11-8-18
//Modified: 1-29-19
//Modified: 1-30-19
//This file contains the declarations and implementations to several algoritms that I have found useful
/*
Copyright (C) 2018 Matthew Ellison
@@ -141,7 +141,7 @@ std::vector<T> getNumPrimes(T numberOfPrimes){
//Using possiblePrime >= 3 to make sure it doesn't loop back around in an overflow error and create an infinite loop
for(T possiblePrime = 3;(primes.size() < numberOfPrimes) && (possiblePrime >= 3);possiblePrime += 2){
//Step through every element in the current primes. If you don't find anything that divides it, it must be a prime itself
for(uint64_t cnt = 0;cnt < primes.size();++cnt){
for(uint64_t cnt = 0;(cnt < primes.size()) && ((primes.at(cnt) * primes.at(cnt)) < possiblePrime);++cnt){
if((possiblePrime % primes.at(cnt)) == 0){
foundFactor = true;
break;