npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fast-prime

v0.1.0

Published

Fastest Prime Number Calculation logic for nodejs and browser (checks, random generator, prime range generator, primes count generator, summation of primes, factorial of primes)

Downloads

42

Maintainers

ganeshkbhatganeshkbhat

Keywords

FastestPrimeNumberCalculationfast primesfast primefastprimesnumbersprime numbersprimeprimesget primeget primesfetch primefetch primescheck primecheck primesfast primefast primesmultiple prime calculation methodsaks prime calculation methodsMersenne prime calculation methodsFermat's little theorem prime calculation methodsConventional prime calculation methodscountfetch all primes from count of numbersrangefetch all primes from range of numberssummationsummation of prime numbersummation of prime numbersfetch summation of all primes from range of numbersfetch factorial of all primes from range of numbersfetch summation of all primes from count of prime numbersfetch factorial of all primes from count of prime numbersfactorialfactorial of prime numberfactorial of prime numbersnode.jsprestored primesprestored primes in jsonprimes datasetprimes .json datasetprestored primes datasetprestored primes dataset in jsonnodejsjavasriptbrowserclientakssquare rootiterativerecursiveMersenne primeFermat's little theoremprimeprimesprimenumberprime numberprime numbersmathsum primesum primessum-primesum-primesprime-jsprime jsprimes-jsnprimeprimalityprimality testnaive testprimesnextprimepreviousprimes nextprime previousprimeutilprime utilprimes-simpleprimes simpleprime factorizationfactorizationnumbersprimalitynumbers primalitysimple-prime-generatorsimple prime generatorfast-prime-generatorfast prime generatorready-primesready primesstored-primesstored primesinteger-sequencesinteger prime sequencesoeismathmathematicintegersequenceseriessquaressquaretriangletriangularnumberstriangular numbersprime helpersprimes helperprimes helpersready-primes-extendedready primes extendedstored-primes-extendedstored primes extendedprime-funprimes-funprime funprimes funmath-iter-sequences-primesmath iter sequences primesmath-iterator-sequences-primesmath iterator sequences primesmath-generator-sequences-primesmath generator sequences primesstdlibstdmathmathematicsmath primesprime integerintprime number sequencesprime number iteratoriterate iterationitergengeneratorprime generatorprimes generatordatasets-primes-100kdatasets primes 100kdatasets primes number 100kdatasets-primes-10kdatasets primes number 10kdatasets-primes-1000kdatasets primes 1000kfast prime generatorgenerate primes in millisecondsdatasetdatasets,Balanced primesBell primesChen primesCircular primesCluster primesCousin primesCuban primesCullen primesDihedral primesEisenstein primes without imaginary partEmirpsEuclid primesEuler irregular primesEuler (pp − 3) irregular primesFactorial primesFermat primesGeneralized Fermat primesFibonacci primesFortunate primesGaussian primesGood primesHappy primesHarmonic primesHiggs primes for squaresHighly cototient primesHome primesIrregular primesirregular primesirregular primesirregular primesIsolated primesLeyland primesLong primesLucas primesLucky primesMersenne primesMersenne divisorsMersenne prime exponentsDouble Mersenne primesGeneralized repunit primesOther generalizations and variationsMills primesMinimal primesNewman–Shanks–Williams primesNon-generous primesPalindromic primesPalindromic wing primesPartition primesPell primesPermutable primesPerrin primesPierpont primesPillai primesPrimes of the form n4 + 1Primeval primesPrimorial primesProth primesPythagorean primesPrime quadrupletsQuartan primesRamanujan primesRegular primesRepunit primesResidue classes of primesSafe primesSelf primes in base 10Sexy primesSmarandache–Wellin primesSolinas primesSophie Germain primesStern primesSuper-primesSupersingular primesThabit primesPrime tripletsTruncatable primeLeft-truncatableRight-truncatableTwo-sidedTwin primesUnique primesWagstaff primesWall–Sun–Sun primesWeakly prime numbersWieferich primesWilson primesWolstenholme primesWoodall primeshttps://en.wikipedia.org/wiki/List_of_prime_numbersprime decompositionprime factorsbricks,factorization,javascript,js,numberprimenumber primegive-me-primeprime-numberPrimeSwapprime-jsprime jsfm-primesprime-package-for-primesprime package for primesfast-primesfast primesFast Prime GenFast Prime Generatorparsegraph-primestest-primegeneratortest prime generatorprimes-multiplication-tableprimes multiplication tablecachedprime number lookupfm-prime-jsfm prime jsfm-prime-pyfm prime pyprimespiceprime spicefast-prime-genfast-prime-generatorfast prime genfast prime generatorprimes-and-factorsprimes and factorsprimes factors numberprimes-factors-numberget-primesget primesprime-package-for-primesprime package for primesprime packageprime package for primesprime package for prime numbersprime package for prime numberprime-package-for-primes@number-theoretic/primes number theoretic primesprimegetprime getprimes getprime-libprime libprimes-simpleprimes simpleget-primesfast-primesprimes-fastprimes fastprimes getpregenerated-primespregenerated primesprimes pregeneratedprime-functionsfunctions primeAdvanced Prime Numbers Functionscached-primesprimes-cachedcached primesis primeisprimetest-primegeneratortest prime generatorprime generatorprime testsprimality testssum primesfactorial primesrange of primesget range of primesget sum of primesget factorial of primesrandom primesget counts or numbers of primesget counts or numbers of primeget range or numbers of primes between rangeget next primeget previous primenext primeprevious primeprimes generator functionstored primesprimes json fileprestored primes json fileprecalculated primes json file

Readme

Fast Prime Calculations

Fastest Prime Number Calculation logic (checks, random generator, prime range generator, primes count generator, summation of primes, factorial of primes, primes generator)

This probably is the BEST solution in the internet as of today 11th March 2022

This same code can be applied in any languages like Python, Go Lang, Java, PHP, Node.js, Javascript, C, C++, .NET, Rust, etc with the same logic and have performance benefits. It is pretty fast based on the number of iterations needed. Performance time checks were not consistent across languages (in my local system - to be direct about wordings). I have not seen this implemented before and has been indigenously done. Feedback and usage is welcome.

Max iterations 16666 for n == 100000 instead of 100000 of conventional way. The iterations counts for different ways for Prime number check 100007 can be seen as follows:

    count: Prime Conventional way for  83 is  81
    Is Prime 83 isPrimeConventionalWay:  True

    count: Prime Squareroot way  83 is  8
    Is Prime 83 isPrimeSquarerootWay:  True

    count: Prime Unconventional way for  83 is  14
    Is Prime 83 prime (SUGGESTED):  True

    count: Prime AKS - Mersenne primes - Fermat's little theorem or whatever way  83 is  2
    Is Prime 83 isprimeAKSWay:  True

    count: Prime Conventional way for  169 is  12
    Is Prime 169 isPrimeConventionalWay:  False

    count: Prime Squareroot way  169 is  12
    Is Prime 169 isPrimeSquarerootWay:  False

    count: Prime Unconventional way for  169 is  1
    Is Prime 169 prime (SUGGESTED):  False

    count: Prime AKS - Mersenne primes - Fermat's little theorem or whatever way  169 is  4
    Is Prime 169 isprimeAKSWay:  False

    count: Prime Conventional way for  100007 is  96
    Is Prime 100007 isPrimeConventionalWay:  False

    count: Prime Squareroot way  100007 is  96
    Is Prime 100007 isPrimeSquarerootWay:  False

    count: Prime Unconventional way for  100007 is  15
    Is Prime 100007 prime (SUGGESTED):  False

    count: Prime AKS - Mersenne primes - Fermat's little theorem or whatever way  100007 is  32
    Is Prime 100007 isprimeAKSWay:  False

    count: Prime Conventional way for  300530164787 is  1180
    Is Prime 300530164787 isPrimeConventionalWay:  False

    count: Prime Squareroot way  300530164787 is  1180
    Is Prime 300530164787 isPrimeSquarerootWay:  False

    count: Prime Unconventional way for  300530164787 is  196
    Is Prime 300530164787 prime (SUGGESTED):  False

    count: Prime AKS - Mersenne primes - Fermat's little theorem or whatever way  300530164787 is  393
    Is Prime 300530164787 isprimeAKSWay:  False

Code Base

Javascript

Javascript Codebase

  • Access Node code using require("fast-prime")
  • Access client (browser code) for just basic prime checks using ./node_modules/src/client/primes.js and node_modules/src/client/primes.min.js
  • Access client (browser code) using ./node_modules/src/client/primes.all.js and node_modules/src/client/primes.all.min.js
  • Access client (browser code) using cdn https://unpkg.com/fast-prime@{version}/src/client/primes.all.js. Example https://unpkg.com/[email protected]/src/client/primes.all.min.js
  • Access client (browser code) smaller non optimised size using ./node_modules/src/client/primes.ip.js and node_modules/src/client/primes.ip.min.js
  • Access client (browser code) smaller non optimised using cdn https://unpkg.com/fast-prime@{version}/src/client/primes.ip.js. Example https://unpkg.com/[email protected]/src/client/primes.ip.min.js
  • Demos

Features of the Library

  • Different ways of prime number checks (isprime)

      - Fast prime (Recommended innovative function)
    
      - Iterative/Recursive (Conventional iterative way)
    
      - SquareRoot (AKS - Mersenne primes - Fermat's little theorem)
  • Different ways of getting primes (using all above different ways)

      - Fetch prime between two number range (min - max)
    
      - Fetch counts (numbers) of prime starting from any number
    
      - Random prime number generator
    
      - Optimized function with pre-calculated stored values (< 10000, < 100000, < 1000000)
    
              - Stored value calculation Failover to JIT calculation using above formulaes
  • Different ways of getting summation of primes (using all above different ways)

      - Fetch summation of prime between two number range (min - max)
    
      - Fetch summation of counts (numbers) of prime starting from any number
    
      - Fetch summation of Custom array provided [TODO]
    
      - Fetch factorial - Optimized function with pre-calculated stored values (< 10000, < 100000, < 1000000)
    
              - Stored value calculation Failover to JIT calculation using above formulaes
  • Different ways of getting factorial of primes (using all above different ways)

      - Fetch factorial of prime between two number range (min - max)
    
      - Fetch factorial of counts (numbers) of prime starting from any number
    
      - Fetch factorial of Custom array provided [TODO]
    
      - Fetch factorial - Optimized function with pre-calculated stored values (< 10000, < 100000, < 1000000)
    
              - Stored value calculation Failover to JIT calculation using above formulaes


// Usage API for node.js
// Check demos folder for usage in the github repos
// https://github.com/ganeshkbhat/fastprimenumbers/tree/main/nodejs/demos

require("fast-prime").fast // Recommended or Suggested way
require("fast-prime").prime // Recommended or Suggested way
require("fast-prime").recursive
require("fast-prime").sqrootExpressive
require("fast-prime").sqroot


require("fast-prime").count.alternateWays
require("fast-prime").count.alternateWaysOptimized (async - promise)
require("fast-prime").count.fast
require("fast-prime").count.fastOptimized (async - promise)

require("fast-prime").range.alternateWays
require("fast-prime").range.alternateWaysOptimized (async - promise)
require("fast-prime").range.fast
require("fast-prime").range.fastOptimized (async - promise)

require("fast-prime").sum.alternateWaysCount
require("fast-prime").sum.alternateWaysCountOptimized (async - promise)
require("fast-prime").sum.alternateWaysRange
require("fast-prime").sum.alternateWaysRangeOptimized (async - promise)
require("fast-prime").sum.fastCount
require("fast-prime").sum.fastCountOptimized (async - promise)
require("fast-prime").sum.fastRange
require("fast-prime").sum.fastRangeOptimized (async - promise)

require("fast-prime").factorial.factorial
require("fast-prime").factorial.alternateWaysCount
require("fast-prime").factorial.alternateWaysCountOptimized (async - promise)
require("fast-prime").factorial.alternateWaysRange
require("fast-prime").factorial.alternateWaysRangeOptimized (async - promise)
require("fast-prime").factorial.fastCount
require("fast-prime").factorial.fastCountOptimized (async - promise)
require("fast-prime").factorial.fastRange
require("fast-prime").factorial.fastRangeOptimized (async - promise)



// Usage API for client
// Check demos folder for usage in the github repos
// https://github.com/ganeshkbhat/fastprimenumbers/tree/main/nodejs/demos


primes().fast // Recommended or Suggested way
primes().primes // Recommended or Suggested way
primes().recursive
primes().sqrootExpressive
primes().sqroot


primesCount().alternateWays
primesCount().alternateWaysOptimized (async - promise)
primesCount().fast
primesCount().fastOptimized (async - promise)

primesRange().alternateWays
primesRange().alternateWaysOptimized (async - promise)
primesRange().fast
primesRange().fastOptimized (async - promise)

primesSum().alternateWaysCount
primesSum().alternateWaysCountOptimized (async - promise)
primesSum().alternateWaysRange
primesSum().alternateWaysRangeOptimized (async - promise)
primesSum().fastCount
primesSum().fastCountOptimized (async - promise)
primesSum().fastRange
primesSum().fastRangeOptimized (async - promise)

primesFactorial().factorial
primesFactorial().alternateWaysCount
primesFactorial().alternateWaysCountOptimized (async - promise)
primesFactorial().alternateWaysRange
primesFactorial().alternateWaysRangeOptimized (async - promise)
primesFactorial().fastCount
primesFactorial().fastCountOptimized (async - promise)
primesFactorial().fastRange
primesFactorial().fastRangeOptimized (async - promise)

Python

Python Codebase

Stack overflow Link for Calculations

LICENSE

Custom Crediting License PROPRIETARY LICENSE AGREEMENT ONLY

TODO

  • [D] Add summation of array of primes using (range, count)
  • Add summation of array of primes using custom prime numbers
  • [D] Add factorial of array of primes using (range, count)
  • Add factorial of array of primes using custom prime numbers
  • Consider adding random prime generator
  • Consider adding generator using generator functions
  • [D] Consider adding fetching primes from remote api for stored primes
  • Consider adding support for very large prime numbers (checks, range, count, sum, factorial, random) and related generators
  • Consider adding support for very large random prime generator
  • Adding following (all) APIs to Javascript, Typescript, Python, Java
  • Adding all APIs to Go, TS (Consider C#, Rust, C, Cpp)
  • Consider adding function to library

const primes = require("fast-primes")
primes().isPrime
primes().sum
primes().range
primes().count
primes().factorial