Kth root using binary search problem

I am facing time limit exceeded problem with my code. How can I optimise my solution?
Here is the code:
#include
#include<math.h>
using namespace std;

int main() {
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n,k,res;
cin>>n>>k;
if(k==1)
res=n;
else{
int start=0,end=n/2,mid;
while(start<=end)
{
mid=(start+end)/2;
if(pow(mid,k)==n)
res=mid;
else if(pow(mid,k)>n)
end=mid-1;
else
{
start=mid+1;
res=mid;
}
}
}
cout<<res<<endl;
}
return 0;
}

Hey Megha, check the constraints provided in the problem carefully as the value of n can be large so you are supposed to use long long int instead of int. I have optimized your code you can refer this.

Hey can you Explain the part inside While(s<=e) because we always take m=(s+e)/2 , but you’ve taken m=(s+e+1)/2 why?
and also s=m why?

Hi Ayush

Please post your doubts using the ask doubt section of your online course.