Created
October 8, 2016 16:40
-
-
Save yevgnenll/e556cace89760d5162734fde537417dc 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 erathos(start, end){ | |
var numbers = init_arr(end); | |
var res = []; | |
for(var i=2; i<numbers.length; i++){ | |
if(numbers[i]){ | |
continue; | |
} | |
res.push(i); | |
for(var j=i*i; j<end+1; j+=i){ | |
numbers[j] = true; | |
} | |
} | |
print_erathos(res, start, end); | |
} | |
function init_arr(length){ | |
var numbers = new Array(length); | |
for(var i=0; i<numbers.length; i++){ | |
numbers[i] = false; | |
} | |
numbers[0] = true; | |
numbers[1] = true; | |
return numbers; | |
} | |
function print_erathos(arr, start, end){ | |
for(var i=0; i<arr.length; i++){ | |
if(arr[i] >= start){ | |
console.log(arr[i]); | |
} | |
} | |
} | |
erathos(11, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment