pub struct PrimeTable { /* private fields */ }
Implementations§
Source§impl PrimeTable
impl PrimeTable
pub fn new(max_n: u32) -> Self
pub fn is_prime(&self, n: u32) -> bool
pub fn primes(&self) -> impl Iterator<Item = u32> + '_
Sourcepub fn trial_division<F>(&self, n: u32, f: F)
pub fn trial_division<F>(&self, n: u32, f: F)
Examples found in repository?
crates/competitive/src/math/prime_table.rs (line 68)
66 pub fn prime_factors(&self, n: u32) -> Vec<(u32, u32)> {
67 let mut factors = vec![];
68 self.trial_division(n, |p, c| factors.push((p, c)));
69 factors
70 }
71 pub fn count_divisors(&self, n: u32) -> u32 {
72 let mut divisor_cnt = 1;
73 self.trial_division(n, |_, cnt| divisor_cnt *= cnt + 1);
74 divisor_cnt
75 }
76 pub fn divisors(&self, n: u32) -> Vec<u32> {
77 let mut d = vec![1u32];
78 self.trial_division(n, |p, c| {
79 let k = d.len();
80 let mut acc = 1;
81 for _ in 0..c {
82 acc *= p;
83 for i in 0..k {
84 d.push(d[i] * acc);
85 }
86 }
87 });
88 d.sort_unstable();
89 d
90 }
pub fn prime_factors(&self, n: u32) -> Vec<(u32, u32)>
pub fn count_divisors(&self, n: u32) -> u32
pub fn divisors(&self, n: u32) -> Vec<u32>
Trait Implementations§
Source§impl Clone for PrimeTable
impl Clone for PrimeTable
Source§fn clone(&self) -> PrimeTable
fn clone(&self) -> PrimeTable
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for PrimeTable
impl RefUnwindSafe for PrimeTable
impl Send for PrimeTable
impl Sync for PrimeTable
impl Unpin for PrimeTable
impl UnwindSafe for PrimeTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more