```
class Solution {
public:
bool isPowerOfThree(int n) {
// With Loop Version
//if(n <= 0) return false;
//while(n%3 == 0){
// n = n/3;
// }
// if(n != 1) return false;
// else return true;
// Without Loop Version
if(n <= 0) return false;
return (pow(3,(int)(log10(n)/log10(3))) == n);
}
};`
```