@algorithm.ts/prime
v4.0.4
Published
A typescript implementation of the Linear-Sieve algorithm for prime numbers.
Downloads
101
Maintainers
Readme
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.
Install
npm
npm install --save @algorithm.ts/primepnpm
pnpm add @algorithm.ts/prime
Usage
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]
