Crates.io | prime_tools |
lib.rs | prime_tools |
version | 0.3.4 |
source | src |
created_at | 2019-10-15 19:50:12.256593 |
updated_at | 2020-10-06 07:07:12.896589 |
description | Generate primes, get prime factors, check primality, and other useful prime-related utilities. |
homepage | |
repository | https://github.com/danmedani/prime_tools |
max_upload_size | |
id | 172787 |
size | 14,564 |
This util provides a few tools for working with prime numbers.
Mostly for personal use with project euler problems. :)
fn get_primes_less_than_x(x: u32) -> Vec<u32>
Generates an ordered list of prime numbers from 2 up to x (exclusive).
Uses the sieve of Eratosthenes under the covers.
fn get_prime_factors_with_counts(x: u32, primes: &Vec<u32>) -> HashMap<u32, u32>
To be used in conjunction with get_primes_less_than_x. Be sure to pass in
primes
at least up to sqrt(x).
fn is_u32_prime(x: u32) -> bool
Figures out if x is prime. This is fast! I've benchmarked it at 2.7 seconds to process 1 million random
u32
s.
fn is_u64_prime(x: u64) -> bool
Figures out if x is prime. This is pretty slow: I've benchmarked it at 26 seconds to process only 200 random
u64
s. :(
fn get_primes_between(min: u64, max: u64) -> Vec<u64>
Generates primes between min (inclusive) and max (exclusive). Uses a modified sieve of eratosthenes.
WARNING #1: This can be very slow if the max is greater than 10^17 ish, or with too large a range.
WARNING #2: This will break if the max is too much higher than 10^19 ish