def iroot_k
import bend-collections@1.0.0.0/src/math/natural.bend as Naturalimport Base
import bend-collections@1.0.0.0/src/math/pow2.bend as P2
235# the largest r with r^k <= n (k >= 1)
236def iroot_k(+n: Nat, +k: Nat) -> Nat:
237 match k:
238 case 0n:
239 0n
240 case 1n:
241 n
242 case 2n+ +kp:
243 search(n, 2n+kp, 0n, P2.pow2t(1n+Nat.div(bit_length(n), 2n+kp)))