@algorithm.ts/sieve-totient
A typescript implementation of the Linear Sieve algorithm for primes numbers and Euler's totient function.
If you are curious about this algorithm, you can visit here for more details.
Install
-
npm
npm install --save @algorithm.ts/sieve-totient
-
yarn
yarn add @algorithm.ts/sieve-totient
-
deno
import sieveTotient from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/sieve-totient/src/index.ts'
Usage
-
Get all prime numbers and totient function values in the range $[2, N)$:
import sieveTotient from '@algorithm.ts/sieve-totient' const [totients, primes] = sieveTotient(10) // => // totients: [0, 1, 1, 2, 2, 4, 2, 6, 4, 6] // primes: [2, 3, 5, 7]