Kth root problem

can you give me the algorithm to solve this question. I am not getting the idea to solve it.

We will apply binary search in this problem. For every possible mid obtained by using binary search we will check of it is the best suitable candidate or not for becoming the Kth root and then we reduce the search space of the binary search according to the mid value. If mid^k is greater than N then we will find the best suitable value from left to mid-1 otherwise we will find much larger value by finding it from mid+1 to right.
Code

i followed the algorithm . It is compiled successfully but giving the wrong output.

#include<bits/stdc++.h> using namespace std; int greatestinteger(int n,int k) { int s = 0; int e = n; int x = 0; while(s<=e) { int mid = (s+e)/2; if(mid^k<=n) { return mid; } if(mid^k>n) { x = mid; e = mid-1; } else { s = mid+1; } } return x; } int main() { int T; cin>>T; while(T–) { int n,k; cin>>n>>k; cout<<greatestinteger(n,k)<<endl; } return 0; }

please, check the provided code for the correct implementation.