Sir which line I need to change , Why should be changed please explain me sir because I have given 2 day to solve the problem but still getting wrong answer help sir

import java.util.*;

public class Main{

public static void main(String args[]){

    Scanner sc = new Scanner(System.in);

    int t = sc.nextInt();

    int n = sc.nextInt();
    int k = sc.nextInt();
    int arr [] = new int [ k- n];
    for(int i = k ; i< n ; i++){
        arr[i] = sc.nextInt();
    }
    kthRoot( arr, n, k);
}

public static void kthRoot( int arr[] , int n, int k){
    int left = k ;
    int right = n ;
    int ans ;
    int mid ;
    while (left < right){
         mid = (left + right)/2 ;
        long d = mid ^ left;
        if( d <= n){
            mid = mid + 1 ;
            left = mid ;
            right = n ;
            ans = mid;
        }
        else if(d >= n){
            mid = mid - 1 ;
            ans = mid ;
            left = k;
            right = mid ;
            
        }
        else
         ans = mid ;
	 
    
    System.out.println(ans);
	}
    
}

}

@abhisheksinghchauhan442,

We will aplly 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.

https://ide.codingblocks.com/s/234800 corrected code.

Example:

initially hi = 10^6, and k = 10, n = 1000000000000000

Now we keep multiplying mid until it either exceeds n or we multiply it k number of times. as seen in this for loop ( for (int i = 1; i <= k; i++) )

Now initially:
mid is 5001 (not our final answer)
lo is 1
hi is 5000

After that we half mid by (lo+hi+1)/2, mid becomes: 2501. But again this is not our final answer. Now, lo is 1 and hi is 2500.
And we check until we get our answer as 31.

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.