1
2
3
4
5
6
7
8
9
10
11
12
13
14
/// Calculates the k-adicity of n, i.e., the number of trailing 0s in a base-k
/// representation.
pub fn k_adicity(k: u64, mut n: u64) -> u32 {
    let mut r = 0;
    while n > 1 {
        if n % k == 0 {
            r += 1;
            n /= k;
        } else {
            return r;
        }
    }
    r
}