Project Euler: Problem 7

This is problem 7 on Project Euler:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6^(th) prime is 13.

What is the 10001^(st) prime number?

Because we have already created a prime number generator this should be quite an easy problem. We simply create a list of prime numbers and read of the required one.

However, because our prime number generator locates prime numbers below a specified threshold, we may have a problem deciding how high to go in calculating our primes. For example if we decide to calculate all the primes below 2000 we may end up with less than 10001 primes. In the end I decided to go with a high number such as 1 million, hoping that there would be at least 10001 primes in this range.

This is my Delphi code:

procedure TfrmMain.Problem7;

Line 3 calculates all the prime numbers up to 1000000 and stores them in our list named lstPrimes. On the next line we simply read of and display the prime number at position 10000 (not 10001 because Delphi counts the elements of a list starting with 0).

Tags: , ,

One Response to “Project Euler: Problem 7”

  1. Gold Price says:

    Many fundamental questions about Mersenne primes remain unresolved. It is not even known whether the set of Mersenne primes is finite or infinite. The Lenstra–Pomerance–Wagstaff conjecture asserts that there are infinitely many Mersenne primes and predicts their order of growth . It is also not known whether infinitely many Mersenne numbers with prime exponents are composite , although this would follow from widely believed conjectures about prime numbers, for example, the infinitude of Sophie Germain primes congruent to 3 ( mod 4 ).