number-theory-js is a library of JavaScript implementations of number theory utilities.
Most of this project's infrastructure was stolen from Jason Mulligan's (avoidwork's) tiny-graph project.
const engine = require('number-theory-js');
console.log(engine.factorize(72)); // [2, 2, 2, 3, 3]
console.log(engine.gcd(35, 84)); // 7
console.log(engine.sieve(20)); // [2, 3, 5, 7, 11, 13, 17, 19]
number-theory-js can be installed from npm and bower, and supports AMD loaders or script tags (e.g. window.sieve
).
Returns the greatest common divisor of integers m
and n
, calculated using Euclid's algorithm
Returns the unique prime factorization of n
as a list of integers
Returns the list of all prime numbers less than n
, calculated using the Sieve of Eratosthenes
Euler's totient function: Returns the list of all positive integers less than n
that are relatively prime to n
Copyright (c) 2018 Tom Weatherhead Licensed under the MIT license