import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
if(t<11 && t>0)
while(t–>0) {
long n = sc.nextLong();
if(n>0) {
int k = sc.nextInt();
if(k>0) {
long x = (long) Math.exp(Math.log(n)/k);
System.out.println(x);
}
}
}
}
}
Kth root. 1 testcase is not passing
Hi @mudit2jain
Please paste your code in ide.codingblocks.com and save it. Then share the link of the code here.
i have tried the binary search approach after unlocking the editorial and it passed the testcases but why i needed to use it. Why i was not getting the right answer by using Math formulas.
you can have a look at my code but what i am asking is why the answer was not coming right using default math functions and formulas. Here is my code with binary search approach which is passing all the testcases https://ide.codingblocks.com/s/82753
Hi @mudit2jain
I was asking to look at your code with math functions and formulas only. Share that code through ide.codingblocks.com and I’ll have a look.
Hey, are you going to reply??
I am having the same doubt,why we have to use binary search if we can get the output by Math formulas
Hey Mudit.
You can use Math formulas, no issue.
But if the input had been :
N = 1000 and K = 3
Your Output : 9
Correct Output : 10
Since you are typecasting, so the value 9.99 gets reduced to 9 instead of 10.
If i take k as float input and then use Math.pow(n,1/k) all test cases are passing.
What is the point of binary search approach if we still have to use Math.pow function inside our code.
why not use the function first and print the answer right away?
@Anupreet9 @mudit2jain you can definitely use math.pow function and solve this problem but what if you are not allowed to use library function like math.pow then it is better to solve using binary search…you must be thinking that after we will be calculating mid then we will require the value of mid^k to decide…so we have to use math.pow function…BUT this value can be found out iteratively…thus try solving this ques using binary search…
NOTE:A value of 10^0.764 cant be found out iteratively but 10^3 can be
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.