what i did seems right to me and it passes 2 testcases but not the last one i’m not getting where i am wrong.
Here’s my code–
#include
#include
using namespace std;
double KthRoot(double n,double k) //double becoz pow() works well with double
{
double s=0,e=n,mid,ans;
while(s<=e)
{
mid=(s+e)/2;
if(pow(mid,k)==n)
{ans=mid;
break;
return ceil(ans);
}
else if(pow(mid,k)<n)
{
ans = mid;
//cout<<ans<<endl;
s = mid+1;
}
else
{
e = mid-1;
}
}
return ceil(ans); //ceil(x)--rouds off to the closest integer.
}
int main() {
int t;
cin>>t;
double n,k;
while(t)
{
cin>>n>>k;
int ans = KthRoot(n,k);
cout<<ans<<endl;
t--;
}
return 0;
}
please help.