@algorithm.ts/prime
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

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/prime
  • yarn

    yarn 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]

Related

Package Sidebar

Install

npm i @algorithm.ts/prime

Weekly Downloads

13

Version

4.0.0

License

MIT

Unpacked Size

15.4 kB

Total Files

8

Last publish

Collaborators

  • lemonclown