Last active
December 10, 2015 12:49
-
-
Save seriusokhatsky/150183bb33e623f5deb3 to your computer and use it in GitHub Desktop.
Find Nth prime number
This file contains hidden or 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
var g = 0; | |
var n = 10001; | |
var i = 1; | |
var isPrime = function(x) { | |
if( x < 2) return false; | |
if(x < 4) return true; | |
if( x % 3 == 0 || x % 2 == 0) return false; | |
for(var i = 2; i <= Math.floor( Math.sqrt(x)); i++) { | |
if(x%i == 0) return false; | |
} | |
return true; | |
} | |
while(g < n) { | |
i++; | |
if(isPrime(i)) g++; | |
} | |
console.log(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment