Check if one integer is an integer power of another

后端 未结 13 1467
臣服心动
臣服心动 2020-11-27 05:15

This is an interview question: \"Given 2 integers x and y, check if x is an integer power of y\" (e.g. for x = 8 and y = 2 the answer is \"true\", and for x = 10 and y = 2 \

相关标签:
13条回答
  • 2020-11-27 05:50
        double a=8;
        double b=64;
    
        double n = Math.log(b)/Math.log(a);
        double e = Math.ceil(n);
    
        if((n/e) == 1){
            System.out.println("true");
        } else{
           System.out.println("false");
        }
    
    0 讨论(0)
提交回复
热议问题