Kth root question

Hi,

my code is giving the right answer for smaller inputs but giving a wrong answer for larger numbers. Can you please check and help me with the fault in my code?

Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
for (int i = 0; i < testCase; i++) {
long n = sc.nextLong();
int k = sc.nextInt();
long x = 0;
long upper = n;
long lower = 0;
while(lower <= upper) {
long mid = (upper + lower) / 2;
if(isValid(n, k, mid)) {
x = mid;
lower = mid + 1;
}else {
upper = mid - 1;
}
}
System.out.println(x);
}

}

public static boolean isValid (long n, int k, long m) {
	long val = m;
	for (int i = 1; i < k; i++) {
		val = val * m;
	}
	if(val > n) {
		return false;
	}
	return true;

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.

Hello,
Thank you for your reply but my doubt was answered.