Swiggy delivery and pricing services may need approximate roots when evaluating geometric scaling factors. Given a nonnegative number x and a positive integer n, compute the real value r such that r^n = x within an absolute error of 1e-7.
Implement the function using binary search. Do not use a built-in root, logarithm, or exponentiation function to directly calculate the answer.
x and a positive integer n.x^(1/n).abs(result - x^(1/n)) <= 1e-7.x >= 0 and n >= 1.def nth_root(x, n):