solve problem 7

This commit is contained in:
Colin McMillen 2020-11-17 14:56:10 -05:00
parent 7d323062a4
commit f0e78c34cf

View File

@ -58,6 +58,19 @@ namespace Euler {
return primes; return primes;
} }
static List<long> FirstNPrimes(long n) {
var primes = new List<long>();
primes.Add(2);
for (int i = 3; ; i += 2) {
if (IsPrime(i, primes)) {
primes.Add(i);
if (primes.Count == n) {
return primes;
}
}
}
}
static long Problem3() { static long Problem3() {
long target = 600_851_475_143; long target = 600_851_475_143;
long targetSqrt = (long) Math.Sqrt(target); long targetSqrt = (long) Math.Sqrt(target);
@ -120,8 +133,13 @@ namespace Euler {
return sum * sum - sumSq; return sum * sum - sumSq;
} }
static long Problem7() {
List<long> primes = FirstNPrimes(10001);
return primes[primes.Count - 1];
}
static void Main(string[] args) { static void Main(string[] args) {
WriteLine(Problem6()); WriteLine(Problem7());
} }
} }
} }