(* "prime" logarithms and p-parts. *)
Definition logn p m := if prime p then logn_rec p m m else 0.

Lemma logn_count_dvd p n : prime p -> logn p n = \sum_(1 <= k < n) (p ^ k %| n).
Definition trunc_log p n :=
let fix loop n k :=
if k is k'.+1 then if p <= n then (loop (n %/ p) k').+1 else 0 else 0
in loop n n.