Last active
August 29, 2015 14:20
-
-
Save Aleksey-Danchin/376c1736a5672f69ff3d 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 getSimpleArray (N) { | |
var preparation = new Int8Array(N + 1), retArray = [], i, j; | |
if (N >= 2) retArray.push(2); | |
for (i = 3; i <= N; i += 2) { | |
if (preparation[i] !== 0) continue; | |
retArray.push(i); | |
j = i * 2; | |
while (j <= N) { | |
preparation[j] = 1; | |
j += i; | |
} | |
} | |
return retArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment