kumikill
3/30/2016 - 3:34 PM

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?

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?

using System;
					
public class Program
{
	public static void Main()
	{
		int i = 0;
		int prime = 0;
		
		do
		{
			prime += IsPrime(i) ? 1 : 0;
			i++;
		} while (prime != 10001);
		
		Console.WriteLine(--i);
	}
	
	static bool IsPrime(int n)
	{
		int bound = (int)Math.Sqrt(n);
	
		if (n == 0 || n == 1) return false;
	
		for (int i = 2; i <= bound; ++i)
			if (n % i == 0) return false;
	
		return true;
	}
}