#primes #math #factors #eratosthenes

prime_tools

Generate primes, get prime factors, check primality, and other useful prime-related utilities

5 releases

✓ Uses Rust 2018 edition

0.2.2 Oct 19, 2019
0.2.1 Oct 18, 2019
0.1.3 Oct 15, 2019
0.1.1 Oct 15, 2019
0.1.0 Oct 15, 2019

#152 in Math

Download history 11/week @ 2019-12-02 133/week @ 2019-12-09 6/week @ 2019-12-23 8/week @ 2020-01-06 36/week @ 2020-01-13 36/week @ 2020-01-20 17/week @ 2020-01-27 52/week @ 2020-02-03 57/week @ 2020-02-10 109/week @ 2020-02-17 82/week @ 2020-02-24 44/week @ 2020-03-02 127/week @ 2020-03-09 51/week @ 2020-03-16

116 downloads per month

MIT license

10KB
194 lines

prime_tools Crate Build Status

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 u32s.

fn is_u64_prime(x: u32) -> bool

Figures out if x is prime. This is pretty slow: I've benchmarked it at 26 seconds to process only 200 random u64s. :(

Dependencies

~480KB