Last active
August 29, 2015 14:10
-
-
Save simon0191/e42a4d74f7e3343935ae to your computer and use it in GitHub Desktop.
primes
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
var isPrime = {}; | |
function main(n) { | |
for(var i = 0;i<=n;++i) isPrime[i] = true; | |
isPrime[0] = isPrime[1] = false; | |
var sol = []; | |
for(var i = 2;i<=n;++i) { | |
if(isPrime[i]) { | |
sol.push(i); | |
for(var j = i*i;j<=n;j+=i) { | |
isPrime[j] = false; | |
} | |
} | |
} | |
return sol; | |
}; | |
//console.log(main(200)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment