solve problem 10

This commit is contained in:
Colin McMillen 2020-11-18 18:31:16 -05:00
parent 261511f44c
commit e7faccb57d

View File

@ -57,6 +57,7 @@ namespace Euler {
primes.Add(2); primes.Add(2);
for (int i = 3; i <= num; i += 2) { for (int i = 3; i <= num; i += 2) {
if (IsPrime(i, primes)) { if (IsPrime(i, primes)) {
WriteLine(i);
primes.Add(i); primes.Add(i);
} }
} }
@ -212,8 +213,19 @@ namespace Euler {
return 0; return 0;
} }
[Fact]
static long Problem10() {
List<long> primes = PrimesUpThrough(2_000_000);
long sum = 0;
foreach (long prime in primes) {
sum += prime;
}
Assert.Equal(142913828922, sum);
return sum;
}
static void Main(string[] args) { static void Main(string[] args) {
WriteLine(Problem9()); WriteLine(Problem10());
} }
} }
} }