Here is the math:

log(n) / log(3) <==> log(3)^x / log(3) for n == 3 ^ x, and x is integer.

Use log formula to bring x to front, we have x*log(3) / log(3), which is equal to x.

We only need to check if x is an whole number by using floor(x) == x

```
class Solution {
public:
bool isPowerOfThree(int n) {
if(n == 0) return false;
double x = log10(n) / log10(3);
return floor(x) == x;
}
};
```