malachite-base 0.4.6

A collection of utilities, including new arithmetic traits and iterators that generate all values of a type
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::num::basic::unsigneds::PrimitiveUnsigned;

pub fn checked_primorial_naive<T: PrimitiveUnsigned>(n: u64) -> Option<T> {
    let n = T::try_from(n).ok()?;
    let mut f = T::ONE;
    for p in T::primes().take_while(|&p| p <= n) {
        f = f.checked_mul(p)?;
    }
    Some(f)
}

pub fn checked_product_of_first_n_primes_naive<T: PrimitiveUnsigned>(n: u64) -> Option<T> {
    let mut f = T::ONE;
    for p in T::primes().take(usize::try_from(n).ok()?) {
        f = f.checked_mul(p)?;
    }
    Some(f)
}