Created
July 14, 2014 19:21
-
-
Save sota1235/c010c337767bc1e9325d to your computer and use it in GitHub Desktop.
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
| function sieve(n) { | |
| // make flag list | |
| var num = [false, false]; | |
| for(i=0;i<n-2;i++) { | |
| num.push(true); | |
| } | |
| for(i=2;i<=Math.sqrt(n);i++) { | |
| if(num[i]) { | |
| for(j=i*i;j<n;j+=i){ | |
| num[j] = false; | |
| } | |
| } | |
| } | |
| return num; | |
| } | |
| list = sieve(999999); | |
| ans = []; | |
| for(i=2;i<list.length;i++){ | |
| if(list[i]) { | |
| ans.push(i); | |
| } | |
| } | |
| console.log(ans); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment