fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int n=3; int m=20;
  14.  
  15. int l=1;
  16. int r=m;
  17. int flag=0;
  18. int ans=-1;
  19. while(l<=r && m>0){
  20. int res=1;
  21. int mid=(l+r)/2;
  22. for(int i=0;i<n;i++){
  23. res=res*mid;
  24. }
  25. if(res==m){
  26. ans=mid;
  27. break;
  28. }
  29. else if(res>m){
  30. r=mid-1;
  31. }
  32. else{
  33. l=mid+1;
  34. }
  35. }
  36. System.out.println(ans);
  37. }
  38. }
  39.  
Success #stdin #stdout 0.07s 16544KB
stdin
Standard input is empty
stdout
-1