bool isPowerOfThree(int n) {
if (n<=0) return false;
int t = pow(3,(int)(log(INT_MAX)/log(3)));
return (t%n == 0);
}
t is maximum power of three
@piyush31 It finds the largest power of 3 less than INT_MAX first, and then checks if it is divisible by n. log(INT_MAX)/log(3) equals to log3(INT_MAX)