Here is the code:- https://ide.codingblocks.com/s/423266, don’t know how to implement it in correct way, please make me clear the question and also specify the error or the approach to do it correctly.
Kth Root Question
You are given two integers n and k. Find the greatest integer x, such that, x^k <= n.
Input: N = 27, K = 3
Output: 3
Input: N = 36, K = 3
Output: 3
Reference Code
#include<bits/stdc++.h>
using namespace std;
#define int long long int
bool isCorrect(int mid,int n,int k){
// here we check mid^k<=n or not
if(pow(mid,k)<=n)return true;
else return false;
}
int32_t main(){
int t;cin>>t;
while(t--){
int n;cin>>n;
int k;cin>>k;
int s=1,e=n;
int ans;
while(s<=e){
int mid=(s+e)/2;
if(isCorrect(mid,n,k)){
s=mid+1;
ans=mid;
}
else e=mid-1;
}
cout<<ans<<endl;
}
return 0;
}
i hope it’s now clear
if you have any further doubt feel free to ask
Can you please give an explanation of how the output is 3 for the example provided, n=27 and k=3, am not able to get this part only as how the output is being framed.
you have to just put the values in this expression to verify the result