public void SieveOfEratosthenes_10_ReturnsExpectedListOfPrimes() { // Arrange var max = 10; var expectedListOfPrimes = new List <int> { 2, 3, 5, 7 }; // Act var result = PrimeHelper.SieveOfEratosthenes(max); // Result result.Should().BeEquivalentTo(expectedListOfPrimes); }
private void ComputeCandidateConcatenationPrimesForAllPrimesUpToUpperBound() { // If two different primes have sums which are 1 and 2 modulo 3, // then concatening them yields a number which sum is 0 modulo 3. // Hence this concatenation is divisble by 3, so not a prime. // Thus it suffices to consider these cases separately. // Note that 3 can belong to both of these groups, so it is also treated separately. var primes = PrimeHelper.SieveOfEratosthenes(UPPER_BOUND_OF_PRIMES).Select(prime => (int)prime); var firstPrimeGroup = primes.Where(prime => NumberHelper.SumOfDigits(prime) % 3 == 1); var secondPrimeGroup = primes.Where(prime => NumberHelper.SumOfDigits(prime) % 3 == 2); ComputeCandidateConcatenations(firstPrimeGroup.ToList()); ComputeCandidateConcatenations(secondPrimeGroup.ToList()); ComputeCandidateConcatenations(3, primes.ToList()); }
public long ComputeSolution() { return(PrimeHelper.SieveOfEratosthenes(UPPER_BOUND).Sum()); }