Skip to content

Instantly share code, notes, and snippets.

@Dinner1111
Last active August 29, 2015 14:08
Show Gist options
  • Save Dinner1111/0783c7b9bb52f5758e55 to your computer and use it in GitHub Desktop.
Save Dinner1111/0783c7b9bb52f5758e55 to your computer and use it in GitHub Desktop.
/*
* 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?
*/
public static void Run()
{
long prime = 0;
int count = 0;
for (long number = 1; count <= 10001; number += 2)
{
bool isPrime = true;
for (int divisor = 3; divisor < Math.Sqrt(number); divisor += 2)
if (number % divisor == 0)
{
isPrime = false;
continue;
}
if (isPrime)
{
prime = number;
count++;
}
}
Console.WriteLine(prime);
Console.ReadKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment