Skip to content

Instantly share code, notes, and snippets.

@Aleksey-Danchin
Last active August 29, 2015 14:20
Show Gist options
  • Save Aleksey-Danchin/376c1736a5672f69ff3d to your computer and use it in GitHub Desktop.
Save Aleksey-Danchin/376c1736a5672f69ff3d to your computer and use it in GitHub Desktop.
Функция возвращает массив всех простых чисел меньших или равных единственному аргументу.
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