#prime #math #algorithm

primecount

Rust wrapper for https://github.com/kimwalisch/primecount

5 releases

0.2.1 Jul 31, 2022
0.2.0 Jul 31, 2022
0.1.2 Jun 21, 2020
0.1.1 Jun 21, 2020
0.1.0 Jun 21, 2020

#1039 in Algorithms

Custom license

670KB
16K SLoC

C++ 14K SLoC // 0.2% comments Shell 1.5K SLoC // 0.1% comments C 360 SLoC // 0.2% comments Wolfram 254 SLoC Rust 37 SLoC // 0.1% comments Batch 9 SLoC // 0.5% comments

primecount-rs

primecount-rs is a library that provides APIs for counting the primes below an integer x ≤ 10^31 using highly optimized implementations of the combinatorial prime counting algorithms.

It is a rust wrapper around an awesome kimwalisch/primecount library.

References:

API

Add to Cargo.toml of your project:

primecount = "0.2.0"

Examples:

use primecount;

fn main() {
    println!("Primes below 1000 = {}", primecount::pi(1000));
    println!(
        "Numbers below 1000 that are not divisible by 
        any of the first 100 primes (a.k.a. Legendre-sum) = {}",
        primecount::phi(1000, 100)
    );
    println!("10th prime = {}", primecount::nth_prime(10));
}

Contribute

  1. Install cmake
  2. Update primecount dependency:
git submodule update --init --recursive
  1. cargo build to build the library
  2. cargo test to run the tests

No runtime deps