Can u pls tell me what is the mistake in this code if i try for n=1000000000000000 and k=10=

#include
using namespace std;

int kthRoot(long long int n,long long int k)
{
long long int s=0,e=n;
long long int mid;
long long int ans;
while(s<=e)
{
mid=(s+e)/2;
// cout<<mid<<“mid”;
long long int pro=1;
for(int i=0;i<k;i++)
{
pro=pro*mid;
}
// cout<<pro<<“pro”;
if(pro==n)
{
ans=mid;

	}
	 if(pro<n)
	{
		s=mid+1;
		ans=mid;
		
	}
	else
	{
		e=mid-1;
		
	}
}





return ans;

}

int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,k;
cin>>n>>k;
int ans=kthRoot(n,k);
cout<<endl<<ans<<“ans”;
}
return 0;

}

Hey @angivanshikaangi, use pow(mid, k) to calculate pro. Just break when pro == n.

still my ans is not coming

#include
#include<bits/stdc++.h>
using namespace std;

int kthRoot(long long int n,long long int k)
{
long long int s=0,e=n;
long long int mid;
long long int ans;
while(s<=e)
{
mid=(s+e)/2;
// cout<<mid<<“mid”;
long long int pro;
pro=pow(mid,k);

// cout<<pro<<“pro”;
if(pro==n)
{
ans=mid;

	}
	 if(pro<n)
	{
		s=mid+1;
		ans=mid;
		
	}
	else
	{
		e=mid-1;
		
	}
}





return ans;

}

int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,k;
cin>>n>>k;
int ans=kthRoot(n,k);
cout<<endl<<ans<<“ans”;
}
return 0;

}

hey @angivanshikaangi, when pro== n, you need to break from this while loop, after making ans=mid.
And correct you output format too.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.