Kth root from sorting and searching

showing wrong answer.

see in the question constraints are quite large so you need to apply a better approach! Try thinking binary search!

1 Like

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

bool possible(long long int n,long long int k,long int mid)
{
if(pow(mid,k)<=n)
return true;
else
return false;
}

int main()
{
int t;
cin>>t;
long long int n,k;
for(int i=0;i<t;i++)
{
cin>>n>>k;
long long int s = 1;
long long int e = n;
long int ans = s;
while(s<=e)
{
long int mid = (s+e)/2;
if(possible(n,k,mid))
{
ans = mid;
s = mid+1;
}
else
e = mid-1;
}
cout<<ans<<endl;
}
return 0;
}
You can also see my code for reference!

1 Like

Can you please tell me how to share the code via link as you have shared. I dont know how to do it. :roll_eyes:

yah sure! so basically you write code on coding blocks ide then click the file button right above the code and save your code and then you can simply copy the link and just paste it in doubt blocks ! :slight_smile: i hope it will help you.

1 Like