func isPowerOfThree(n int) bool { if n <= 0 { // The power is non-negative. return false } return 1162261467 % n == 0 // A magic number! (Actually, is the maximum of pow(3, x) in [1, 1<<32-1]) }