Project Euler - Problem 007

Problem 7 builds on the previous Prime computations and some more LINQ.

Starting with the infinite prime number sequence from Problem 3, we'll create a new helper method that returns the Nth prime.

              private static BigInteger NthPrime(BigInteger n)
              {
                  return Numbers.Primes
                                .SkipWhile((value, index) => { return index < n - 1; })
                                .Take(1)
                                .Single();
              }
          

Which allows for a nice and simple method to get the answer.

              private static BigInteger GetAnswerToProblem7()
              {
                  return Mathematics.NthPrime(10001);
              }
          


Tags

  • .NET
  • Project Euler

Revisions

  • 4/22/2013 - Article published.