Wondering what’s next for npm?Check out our public roadmap! »

antiprime
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

antiprime

Build Status Coverage Status GitHub issues NPM Licence npm bundle size npm total downloads npm version

Because sometimes we want highly composite numbers.

Installation

npm i --save antiprime

Usage

JavaScript

const { isHighlyComposite } = require('antiprime');
const hc = isHighlyComposite(12);
console.log(hc); //Outputs: true

TypeScript

import { Antiprime } from 'antiprime';
const ap = new Antiprime(33);
console.log(ap.isAntiprime()); //Outputs: false

API

new Antiprime(n);
new HighlyCompositeNumber(n); //alias

Creates a new Antiprime class object.

Properties

value

The positive integer value currently stored in the Antiprime object.

Functions

previousAntiprime()
previousHighlyCompositeNumber() //alias

Returns a new Antiprime object where value is equal to the next lowest Antiprime number.

nextAntiprime()
nextHighlyCompositeNumber() //alias

Returns a new Antiprime object where value is equal to the next largest Antiprime number.

getFactors()

Returns an array of numbers that include all factors including the 1 and value.

getPrimeFactors()

Returns an array of objects with properties factor and exponent of all prime factors.


As well as the Antiprime class, there are exported functions that can used to test numbers without calculating other properties.

Functions

factors(n)

Takes an input integer n and returns all factors of the input as an array of numbers.

isAntiprime(n, pf)
isHighlyComposite(n, pf) //alias

Takes an input integer n and returns true if the input is highly composite; false otherwise. Optional input pf is the output to the primeFactors function. This is provided to reduce computational overhead in the case that primeFactors has been calculated for n previously.

isAntiprimeCandidate(n, pf)

Takes an input integer n and returns true if the input is a candidate for a highly composite number; false otherwise. Optional input pf is the output to the primeFactors function. This is provided to reduce computational overhead in the case that primeFactors has been calculated for n previously.

A candidate is a number that meets the following criteria:

  • The k prime factors are equal to the first k prime numbers.
  • The exponent of each prime factor does not increase as the magnitude of prime factors increases.
  • The exponent of the final prime factor is 1.
  • n is one of the special cases: 4 or 36.
isConsecutivePrimeFactors(pf)

Takes the output of primeFactors and returns true if the k prime factors are equal to the first k prime numbers; false otherwise.

isPrime(n)

Returns true if the input number n is prime; false otherwise.

isPrimeExponentsReducing(pf)

Takes the output of primeFactors and returns true if the exponent of each prime factor does not increase as the magnitude of prime factors increases; false otherwise.

nextPrime(n)

Returns the next prime number larger than the magnitude of n.

primeFactors(n)

Returns an array of objects containing the properties factor and magnitude representing the prime factors of n and their magnitude.

Test

npm run test

Install

npm i antiprime

DownloadsWeekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

38.6 kB

Total Files

44

Last publish

Collaborators

  • avatar