code: def mpf_nthroot(s, n, prec, rnd=round_fast):
      """nth-root of a positive number
  
      Use the Newton method when faster, otherwise use x**(1/n)
      """
      sign, man, exp, bc = s
      if sign:
          raise ComplexResult("nth root of a negative number")
      if not man:
          if s == fnan:
              return fnan
          if s == fzero:
              if n > 0:
                  return fzero
              if n == 0:
                  return fone
              return finf
          # Infinity
          if not n:
              return fnan
          if n < 0:
              return fzero
          return finf
      flag_inverse = False
      if n < 2:
          if n == 0:
              return fone
          if n == 1:
              return mpf_pos(s, prec, rnd)
          if n == -1:
              return mpf_div(fone, s, prec, rnd)
          # n < 0
          rnd = reciprocal_rnd[rnd]
          flag_inverse = True
          extra_inverse = 5
          prec += extra_inverse
          n = -n
      if n > 20 and (n >= 20000 or prec < int(233 + 28.3 * n**0.62)):
          prec2 = prec + 10
          fn = from_int(n)
          nth = mpf_rdiv_int(1, fn, prec2)
          r = mpf_pow(s, nth, prec2, rnd)
          s = normalize(r[0], r[1], r[2], r[3], prec, rnd)
          if flag_inverse:
              return mpf_div(fone, s, prec - extra_inverse, rnd)
          else:
              return s
      # Convert to a fixed-point number with prec2 bits.
      prec2 = prec + 2 * n - (prec % n)
      # a few tests indicate that
      # for 10 < n < 10**4 a bit more precision is needed
      if n > 10:
          prec2 += prec2 // 10
          prec2 = prec2 - prec2 % n
      # Mantissa may have more bits than we need. Trim it down.
      shift = bc - prec2
      # Adjust exponents to make prec2 and exp+shift multiples of n.
      sign1 = 0
      es = exp + shift
      if es < 0:
          sign1 = 1
          es = -es
      if sign1:
          shift += es % n
      else:
          shift -= es % n
      man = rshift(man, shift)
      extra = 10
      exp1 = ((exp + shift - (n - 1) * prec2) // n) - extra
      rnd_shift = 0
      if flag_inverse:
          if rnd == "u" or rnd == "c":
              rnd_shift = 1
      else:
          if rnd == "d" or rnd == "f":
              rnd_shift = 1
      man = nthroot_fixed(man + rnd_shift, n, prec2, exp1)
      s = from_man_exp(man, exp1, prec, rnd)
      if flag_inverse:
          return mpf_div(fone, s, prec - extra_inverse, rnd)
      else:
          return s
  
imports: import math
  from bisect import bisect
  from .backend import xrange
  from .backend import MPZ, MPZ_ZERO, MPZ_ONE, MPZ_TWO, MPZ_FIVE, BACKEND
  from .libmpf import round_floor, round_ceiling, round_down, round_up, round_nearest, round_fast, ComplexResult, bitcount, bctable, lshift, rshift, giant_steps, sqrt_fixed, from_int, to_int, from_man_exp, to_fixed, to_float, from_float, from_rational, normalize, fzero, fone, fnone, fhalf, finf, fninf, fnan, mpf_cmp, mpf_sign, mpf_abs, mpf_pos, mpf_neg, mpf_add, mpf_sub, mpf_mul, mpf_div, mpf_shift, mpf_rdiv_int, mpf_pow_int, mpf_sqrt, reciprocal_rnd, negative_rnd, mpf_perturb, isqrt_fast
  from .libintmath import ifib
label_desc: Use image node_id 19 for calling a global function with example usage: mpf_nthroot(s, n, prec, rnd) and returns: finf, mpf_div, s, fnan, finf, fnan, fzero, fone, mpf_pos, mpf_div, mpf_div, s, fzero, fone