Skip to main content

find_factor

Function find_factor 

Source
fn find_factor(n: u64) -> Option<u64>
Examples found in repository?
crates/competitive/src/math/prime_factors.rs (line 86)
72pub fn prime_factors_flatten(mut n: u64) -> Vec<u64> {
73    if n == 0 {
74        return vec![];
75    }
76    let k = n.trailing_zeros();
77    let mut res = vec![2; k as usize];
78    n >>= k;
79    while n.is_multiple_of(3) {
80        res.push(3);
81        n /= 3;
82    }
83    if n != 1 {
84        let mut c = vec![n];
85        while let Some(n) = c.pop() {
86            if let Some(m) = find_factor(n) {
87                c.push(m);
88                c.push(n / m);
89            } else {
90                res.push(n);
91            }
92        }
93    }
94    res.sort_unstable();
95    res
96}