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;
}