https://github.com/uutils/num-prime
Generic and optimized primality test, factorization and various number theoretic functions with arbitrary precision based on `num`.
https://github.com/uutils/num-prime
Last synced: 3 months ago
JSON representation
Generic and optimized primality test, factorization and various number theoretic functions with arbitrary precision based on `num`.
- Host: GitHub
- URL: https://github.com/uutils/num-prime
- Owner: uutils
- License: apache-2.0
- Created: 2022-01-08T04:34:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-02-18T21:34:19.000Z (3 months ago)
- Last Synced: 2026-02-18T23:49:00.332Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 521 KB
- Stars: 25
- Watchers: 3
- Forks: 14
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# num-prime
[](https://crates.io/crates/num-prime)
[](https://codspeed.io/uutils/num-prime?utm_source=badge)
[](https://discord.gg/wQVJbvJ)
[](https://github.com/uutils/num-prime/blob/main/LICENSE)
[](https://deps.rs/repo/github/uutils/num-prime)
[](https://codecov.io/gh/uutils/num-prime)
This crate provides utilities for prime number related functionalities:
- Primality testing
- Deterministic primality check of `u64` integers (using a very fast hashing algorithm)
- Fermat probable prime test
- Miller-rabin probable prime test
- (strong/extra strong) Lucas probable prime test
- Baillie-PSW test
- Sophie Germain safe prime test
- Primes generation and indexing
- A naive implementation of the sieve of Eratosthenes
- Unified API to support other prime generation backends
- Generate random (safe) primes
- Find previous/next prime
- Integer factorization
- Trial division
- Pollard's rho algorithm
- Shanks's square forms factorization (SQUFOF)
- Fast factorization of `u64` and `u128` integers
- Number theoretic functions
- Prime Pi function (number of primes under limit), its estimation and its bounds
- Nth prime, its estimation and its bounds
- Moebius function
- Divisor Sigma function *([in examples](./examples/divisor_sigma.rs))*
- Prime Omega function *([in examples](./examples/prime_omega.rs))*
It's based on the `num` creates and most functions are decently optimized with pre-computed tables (see **[benchmark results here](./PERFORMANCE.md)**).