Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
unsigned long get_nth_prime_without_sieve(unsigned long n) {
if (n == 0) return 0;
if (n == 1) return 2;
unsigned long prime_num = 3;
unsigned long local_n = 2; // 2th prime number is 3
while (local_n != n) {
// check next prime number candidate
prime_num += 2; // 3,5,7,9... check only odd numbers
if (isPrime(prime_num) == true) {
local_n++;
}
}
return prime_num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.