K Root challenge

Please help me out with this challenge.
Following is the code
#include
#include
using namespace std;
int main() {
unsigned long long int result,t,n,k,s,e,m,i,ans=0;
cin>>t;

for(i=0;i<t;i++){
    cin>>n;
    cin>>k;
     s=0;
     e=n;
while(s<=e)
{
    m=(s+e)/2;
   
    result=pow(m,k);
    if(result<=n)
    {
    ans=m;
    s=m+1;
    }
    else if(result>n)
    {
        e=m-1;
    }
}
cout<<ans;
}
return 0;

}

The code is not working for large inputs

eg. 27000000 3 . output is 27000000

yes this will not work on large inputs
you will better know this after printing value of result
correct way to solve this problem is

int t;
    ll n,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        if(k==1)
        {
            cout<<n<<endl;
            continue;
        }
        ll l=1,r=1000000,mid;
        while(l<r)
        {
            mid=l+r+1>>1;
            bool flag=1;
            ll tmp=1;
            for(int i=1;i<=k;i++)
            {
                tmp*=mid;
                if(tmp>n)
                {
                    flag=0;
                    break;
                }
            }
            if(flag)
                l=mid;
            else
                r=mid-1;
        }
        cout<<r<<endl;
    }

but why it is showing same number?
I never assigned that number to ans variable.
thanks

because result is always 0
so our s will increase every time and at end it converge at e

and result is alway 0 because it overflow the range so pow function give some garbage no which is negative but we make unsigned variable so it stores 0

but after some iterations result will become less than n,at that time result should not be 0.

And we have used long long int, then result should not be overflow

thanks

for 27000000
s=0 e=27000000 mid=13500000
let say k=10
then 10^mid will definitely overflow
i hope you understand this
and as result is 0 so mid moves toward e and hence every time mid will increase so it again overflow

i hope you understand
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

but we have to find mid^10 .
will that also overflow?
thnks

yes this will also overflow
you can see 2^10 = 1024
so 13500000^10 = very large no

one last doubt that why we add 1 to calculate mid
and please add the code that u sent
thanks

it will not create any difference

#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
int t;
    ll n,k;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        if(k==1)
        {
            cout<<n<<endl;
            continue;
        }
        ll l=1,r=1000000,mid;
        while(l<r)
        {
            mid=l+r>>1;
            bool flag=1;
            ll tmp=1;
            for(int i=1;i<=k;i++)
            {
                tmp*=mid;
                if(tmp>n)
                {
                    flag=0;
                    break;
                }
            }
            if(flag)
                l=mid;
            else
                r=mid-1;
        }
        cout<<r<<endl;
    }
}

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.