Here’s my code:
`//kth root
#include
#include <bits/stdc++.h>
#include
using namespace std;
typedef long long unsigned llu;
// method returns Nth power of A
double nthRoot(llu A, int N)
{
// intially guessing a random number between
// 0 and 9
double xPre = rand() % 10;
// smaller eps, denotes more accuracy
double eps = 1e-8;
// initializing difference between two
// roots by INT_MAX
double delX = INT_MAX;
// xK denotes current value of x
double xK;
// loop untill we reach desired accuracy
while (delX > eps)
{
// calculating current value from previous
// value by newton's method
xK = ((N - 1.0) * xPre +
(double)A/pow(xPre, N-1)) / (double)N;
delX = abs(xK - xPre);
xPre = xK;
}
return xK;
}
int main() {
int t=0;
cin>>t;
fesetround(FE_DOWNWARD);
for(int i=0;i<t;i++){
llu n=0;
int k=0;
cin>>n>>k;
if(k == 0) {cout<<1<<endl;continue;}
cout<<fixed<<setprecision(0)<<nthRoot(n,k)<<endl;
}
}
`
Two of the test cases are passing however, one of them is failing. Has anybody else tried that problem in practice section > binary search > kth root of a number ?