Last active
August 29, 2015 14:08
-
-
Save Dinner1111/0783c7b9bb52f5758e55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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