Last active
March 21, 2020 09:40
-
-
Save i386net/61486e8abcfaca2a41d9d52dead5e94a to your computer and use it in GitHub Desktop.
решето Эратосфена
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
// let ticks = null; | |
function primes(n) { | |
const a = new Array(n); | |
const ret = []; | |
a.fill(true); | |
// ticks = 0; | |
for (let i = 2; i <= n; i++) { | |
// ticks++; | |
if (a[i]) { | |
ret.push(i); | |
for (let j = i*i; j < n; j+=i) { | |
a[j] = false; | |
// ticks++; | |
} | |
} | |
} | |
// console.log('TICKS: ', ticks); | |
return ret; | |
} | |
let ticks = null; | |
function primes(n) { | |
const a = new Array(n); | |
const ret = []; | |
a.fill(true); | |
ticks = 0; | |
for (let i = 2; i <= n; i++) { | |
ticks++; | |
if (a[i]) { | |
ret.push(i); | |
for (let j = i*i; j < n; j+=i) { | |
a[j] = false; | |
ticks++; | |
} | |
} | |
} | |
console.log('TICKS: ', ticks); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment