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
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