Kth root - Runtime error

Here is the code. Please help with the issue.

#include
#include <math.h>
using namespace std;

int main() {

int t;
cin>>t;

while(t--)
{
	long n,k;
	cin>>n>>k;

	long min=0;
	long max=n;
	long mid = max;

	while(min != max)
	{	
		if(pow(mid,k) > n){
			max = mid-1;
		}
		else if(pow(mid,k) < n)
		{
			min = mid+1;
		}
		else if(k == 1){
			mid = max;
			break;
		}
		else if(pow(mid,k) == n)
		{
			break;
		}

		mid = (min+max)/2;

		
	}

	cout<<mid<<endl;
}

return 0;

}

@abhishekchoudhary You haven’t included the bits/stdc++.h header file. Try including that

@abhishekchoudhary And instead of using the predefined pow function. Make a user defined function yourself.

So I made the changes, it still doesn’t work.
#include
using namespace std;

int power(int x, int k)
{
int ans = 1;
while(k–)
{
ans = x*ans;
}

return ans;

}

int main() {

int t;
cin>>t;

while(t--)
{
	long n,k;
	cin>>n>>k;

	long min=0;
	long max=n;
	long mid = max;

	while(min != max)
	{	
		if(power(mid,k) > n){
			max = mid-1;
		}
		else if(power(mid,k) < n)
		{
			min = mid+1;
		}
		else if(k == 1){
			mid = max;
			break;
		}
		else if(power(mid,k) == n)
		{
			break;
		}

		mid = (min+max)/2;

		
	}

	cout<<mid<<endl;
}

return 0;

}

@abhishekchoudhary Dude you should write the modular exponentiation power function.
Your code will give a tle for larger values of k.
ll power(ll x, ll y , ll m){
long long int res = 1;
x = x % m;
while (y > 0){
if (y & 1)
res =(resx)%MOD;
y = y>>1;
x = (x
x)%MOD;
}
return res;
}
You can use this and modify it according to your needs.