```
This can be generalized for any prime number n.
Lets say we have 2 number m & n.
If m is a power of n then for any number p,
1. For all p<=m
2. m%p = 0 if and only if p is also a power of n
We can use this concept here also. In this case n=3 and m is largest 32bit signed integer which is power of 3 i.e. 1162261467.
bool isPowerOfThree(int p) {
return p>0 && 1162261467%p == 0 ;
}
```