Browse Source

solve problem 7

main
Colin McMillen 11 months ago
parent
commit
f0e78c34cf
  1. 20
      Program.cs

20
Program.cs

@ -58,6 +58,19 @@ namespace Euler {
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() {
long target = 600_851_475_143;
long targetSqrt = (long) Math.Sqrt(target);
@ -120,8 +133,13 @@ namespace Euler {
return sum * sum - sumSq;
}
static long Problem7() {
List<long> primes = FirstNPrimes(10001);
return primes[primes.Count - 1];
}
static void Main(string[] args) {
WriteLine(Problem6());
WriteLine(Problem7());
}
}
}
Loading…
Cancel
Save