public Performance GetPerformance(TestConstraints testConstraints) { Stopwatch sw = new Stopwatch(); var trialDivison = new TrialDivisionByPrimes(); sw.Start(); long prime = trialDivison.Primes.TakeWhile(p => p < testConstraints.Limit).ToList().Last(); return new Performance { RangeLimit = testConstraints.Limit, TimeTaken = sw.ElapsedMilliseconds }; }
public Performance GetPerformance(TestConstraint testConstraints) { var trialDivison = new TrialDivisionByPrimes(); Stopwatch sw = Stopwatch.StartNew(); var primes = trialDivison.Primes.TakeWhile(p => p <= testConstraints.Limit).ToList(); sw.Stop(); return new Performance { RangeLimit = testConstraints.Limit, NoPrimesFound = primes.LongCount(), LastPrimeFound = primes.LastOrDefault(), TimeTaken = sw.ElapsedMilliseconds }; }
List<Performance> GetTrialDivisonPeformanceTimes(long to, long increment) { var performanceValues = new List<Performance>(); for (long i = 1000; i <= to; i += increment) { Stopwatch sw = new Stopwatch(); var trialDivison = new TrialDivisionByPrimes(); sw.Start(); long prime = trialDivison.Primes.TakeWhile(p => p < i).ToList().Last(); var per = new Performance { RangeLimit = i, TimeTaken = sw.ElapsedMilliseconds }; performanceValues.Add(per); } return performanceValues; }
public long LargestPrimeFactorOf(long number) { if (number <= 1) return 0; var td = new TrialDivisionByPrimes(); long largestPrimeFound = 0; foreach (var prime in td.Primes) { if (prime * prime > number) { largestPrimeFound = number; break; } while (number % prime == 0) number = number / prime; } return largestPrimeFound; }
public void Setup() { _trialDivision = new TrialDivisionByPrimes(); }
public long FindNthPrime(int n) { var td = new TrialDivisionByPrimes(); return td.Primes.Skip(n - 1).Take(1).First(); }