public class Solution {
public boolean isPowerOfThree(int n) {
return (n > 0) && ((int)Math.pow(3, 19) % n == 0);
}
}
//因为3是质数、同理5,7也可以用这个方法,但是9不行
// 1162261467 is 3^19, 3^20 is bigger than int
class Solution {
public:
bool isPowerOfThree(int n) {
return fmod(log10(n)/log10(3), 1)==0;
}
};