fn fold_divisors<F>(house_number: usize, f: F) -> u64
where
    F: Fn(u64, u64) -> u64,
{
    let factors = SIEVE.factor(house_number).unwrap();

    fn accumulate<F>(
        sum: &mut u64,
        factors: &Vec<(usize, usize)>,
        factor_idx: usize,
        multiplier: u64,
        f: &F,
    ) where
        F: Fn(u64, u64) -> u64,
    {
        if factor_idx >= factors.len() {
            *sum = f(*sum, multiplier);
            return;
        }
        let (factor, exponent) = factors[factor_idx];
        let factor = factor as u64;
        let mut extra_multiplier = 1;
        for _ in 0..=exponent {
            accumulate(
                sum,
                factors,
                factor_idx + 1,
                multiplier * extra_multiplier,
                f,
            );
            extra_multiplier *= factor;
        }
    }

    let mut sum = 0;
    accumulate(&mut sum, &factors, 0, 1, &f);
    sum
}
/// Iterates over all the positive integer divisors of a number (by doing
/// prime factorization and combinations). It then applies function f over
/// an accumulated value (starting at 0) for each divisor.
Iterates over all the positive integer divisors of a number (by doing
prime factorization and combinations). It then applies function f over
an accumulated value (starting at 0) for each divisor.
Iterates over all the positive integer divisors of a number ( by doing prime factorization and combinations ) . It then applies function f over an accumulated value ( starting at 0 ) for each divisor .
fn fold_divisors<F>(house_number: usize, f: F) -> u64
where
    F: Fn(u64, u64) -> u64,
{
    let factors = SIEVE.factor(house_number).unwrap();
    fn accumulate<F>(
        sum: &mut u64,
        factors: &Vec<(usize, usize)>,
        factor_idx: usize,
        multiplier: u64,
        f: &F,
    ) where
        F: Fn(u64, u64) -> u64,
    {
        if factor_idx >= factors.len() {
            *sum = f(*sum, multiplier);
            return;
        }
        let (factor, exponent) = factors[factor_idx];
        let factor = factor as u64;
        let mut extra_multiplier = 1;
        for _ in 0..=exponent {
            accumulate(
                sum,
                factors,
                factor_idx + 1,
                multiplier * extra_multiplier,
                f,
            );
            extra_multiplier *= factor;
        }
    }
    let mut sum = 0;
    accumulate(&mut sum, &factors, 0, 1, &f);
    sum
}
fn fold_divisors < F > ( house_number : usize , f : F ) -> u64 where F : Fn ( u64 , u64 ) -> u64 , { let factors = SIEVE . factor ( house_number ) . unwrap ( ) ; fn accumulate < F > ( sum : & mut u64 , factors : & Vec < ( usize , usize ) > , factor_idx : usize , multiplier : u64 , f : & F , ) where F : Fn ( u64 , u64 ) -> u64 , { if factor_idx >= factors . len ( ) { * sum = f ( * sum , multiplier ) ; return ; } let ( factor , exponent ) = factors [ factor_idx ] ; let factor = factor as u64 ; let mut extra_multiplier = 1 ; for _ in 0 ..= exponent { accumulate ( sum , factors , factor_idx + 1 , multiplier * extra_multiplier , f , ) ; extra_multiplier *= factor ; } } let mut sum = 0 ; accumulate ( & mut sum , & factors , 0 , 1 , & f ) ; sum }
Iterates over all the positive integer divisors of a number (by doing
prime factorization and combinations).
Iterates over all the positive integer divisors of a number ( by doing prime factorization and combinations ) .
house_number
usize
f
F