Problem 007


Project Euler

10001st prime

Problem 7

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

What is the 10 001st prime number?


This problem is similar to a prime sieve. However, to know which one is the 10001 st prime number means there must be a counter for each prime from the beginning. Again skips all even numbers, a brute force approach is to find the specified prime by remember and check against all the prime numbers come before. Not very efficient algorithm but it didn’t take long with only the 10001st prime. One additional improvement could have done was to skip the check if the remembered prime number is square root of the number that is being checked against.

Advertisements