const_primes

Function prime_pi

Source
pub const fn prime_pi<const N: usize>() -> [usize; N]
Expand description

Returns an array of size N where the value at a given index is how many primes are less than or equal to the index.

Sieves primes with sieve and then counts them.

ยงExample

Basic usage

const COUNTS: [usize; 10] = prime_pi();
assert_eq!(COUNTS, [0, 0, 1, 2, 2, 3, 3, 4, 4, 4]);