#include
using namespace std;
bool check(long long x,long long n,int k)
{
long long product=1;
for(int i=1;i<=k;i++)
{
product*=x;
if(product>n)
return false;
}
return true;
}
long long find_number(long long n,int k)
{
long long min=0;
long long max=n;
long long mid;
long long ans;
while(min<=max)
{
mid=(min+max)/2;
bool x=check(mid,n,k);
if(x)
{
ans=mid;
min=mid+1;
}
else
max=mid-1;
}
return ans;
}
int main()
{
int t,k;
long long n,ans;
cin>>t;
while(t–)
{
cin>>n>>k;
ans=find_number(n,k);
cout<<ans<<endl;
}
return 0;
}
Why i am getting wrong answer?
Just add base cases like when k=2 return sqrt(n) and if k is 1 return n.
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.