fastest method to find nth root of a number : The problem is to find nth root of a number and if the root is an integer i need to print it else i will have to print -1.I had used this method but i get tle.Is there any method faster than the one i have implemented.Here is my code:
                      
                         public class Sqrt {
                                             public static double nthroot(int n, double x) 
                                               {
                                                 return Math.pow(x,1./n);
                                               }
                                             public static void main(String[] args) throws IOException {
                                                 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                                                  int t,n,m;
                                                  double x;
                                                  String[] y;
                                              t=Integer.parseInt(br.readLine());
                                              while(t-->0)
                                                  {
                                                    y=br.readLine().split(" ");
                                                  n=Integer.parseInt(y[1]);//the exp
                                                  m=Integer.parseInt(y[0]);//the number
                                                  x=nthroot(m,n);
                                                  x= BigDecimal.valueOf(x)
                                         .setScale(5, RoundingMode.HALF_UP)
                                        .doubleValue();
                                                 if(x==(int)x)
                                                   {
                                                     System.out.println((int)x);
                                                   }
                                                  else
                                                     {
                                                     System.out.println(-1);
                                                     }
                                          }
                                    }
    
}
                          