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 55)
45pub fn prime_factors_flatten(mut n: u64) -> Vec<u64> {
46    if n == 0 {
47        return vec![];
48    }
49    let k = n.trailing_zeros();
50    let mut res = vec![2; k as usize];
51    n >>= k;
52    if n != 1 {
53        let mut c = vec![n];
54        while let Some(n) = c.pop() {
55            if let Some(m) = find_factor(n) {
56                c.push(m);
57                c.push(n / m);
58            } else {
59                res.push(n);
60            }
61        }
62    }
63    res.sort_unstable();
64    res
65}