Sha256: d2a701fe0a249be27cc6773c91e8ee7d5f1c23af1f2d07ab8a1635fdfa2752f9
Contents?: true
Size: 923 Bytes
Versions: 62
Compression:
Stored size: 923 Bytes
Contents
class Sieve { static primes(limit: number): number[] { if (limit === 2) { return [limit] } const sieve: boolean[] = [] for (let i = 0; i < limit; i++) { sieve[i] = true } const primes: number[] = [] const maxCandidate = Math.floor(Math.sqrt(limit)) for (let candidate = 2; candidate <= maxCandidate + 1; candidate++) { if (!sieve[candidate - 1]) { continue } primes.push(candidate) let multiple = candidate * candidate while (multiple <= limit) { sieve[multiple - 1] = false multiple += candidate } } for (let i = maxCandidate + 1; i <= limit; i++) { if (sieve[i - 1]) { primes.push(i) } } return primes } } export default Sieve
Version data entries
62 entries across 62 versions & 1 rubygems