A typescript implementation of the Linear Sieve algorithm for prime numbers.
If you are curious about this algorithm, you can visit [here][prime] for more details.
-
npm
npm install --save @algorithm.ts/prime
-
yarn
yarn add @algorithm.ts/prime
-
Get all prime numbers in the range
$[2, N)$ :import { sievePrime } from '@algorithm.ts/prime' sievePrime(5) // => [2, 3] sievePrime(6) // => [2, 3, 5] sievePrime(10) // => [2, 3, 5, 7]
-
Get all prime numbers and totient function values in the range
$[2, N)$ :import { sieveTotient } from '@algorithm.ts/prime' const [totients, primes] = sieveTotient(10) // => // totients: [0, 1, 1, 2, 2, 4, 2, 6, 4, 6] // primes: [2, 3, 5, 7]