Kth root of a number

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 ?

here’s my binary search based code for finding Kth root of N

#include
using namespace std;

long long power(long long X,long long N)
{
if(N==0)
return 1;
if(N%2==0)
return power(XX,N/2);
return X
power(X,N-1);
}
long long search(long long N,int K,long long start,long long end)
{
if(start>end)
return -1;
long long mid=(start+end)/2;
long long p=power(mid/1000000000,K); ///checking whether mid^K==N or mid is Kth root of N
if(p==N)
return mid;
else if(p<N)
return search(N,K,mid+1,end);
else
return search(N,K,start,mid-1);
}
int main() {
// your code goes here
long long K,N;
cin>>K>>N;
long long ans=search(N,K,0,N*1000000000);
cout<<ans/1000000000;
return 0;
}

can you save your code in codeblocks ide cuz it’s giving errors in long long power(long long X,long long N) function

https://ide.codingblocks.com/#/s/22565

but this hives wrong answer on submission.

give me the problem link so that i can try…

https://hack.codingblocks.com/contests/c/452/274

https://ide.codingblocks.com/#/s/22939

here’s my solution to this.
Complexity: O(TKlogN)
Approach: Binary search.
Basically i searched for X satisfying X^K<=N in range 0 to sqrt(N) and handled the case of K=1 separately.

https://ide.codingblocks.com/#/s/22943

you can also do this by simply making use of inbuilt power function.

why we are using long double instead of long long in 12th line?