```
class Solution {
public:
int const Max3PowerInt = 1162261467; // 3^19, 3^20 = 3486784401 > MaxInt32
int const MaxInt32 = 2147483647; // 2^31 - 1
bool isPowerOfThree(int n) {
if (n <= 0 || n > Max3PowerInt) return false;
return Max3PowerInt % n == 0;
}
};
```

Typically, Log(x, y) is not O(1), it should be O(ln(N)), which just hides the loop/recursion .