Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: trueExample 2:
Input: 0
Output: falseExample 3:
Input: 9
Output: trueExample 4:
Input: 45
Output: falseFollow up:
Could you do it without using any loop / recursion?
class Solution {
public:
bool isPowerOfThree(int n) {
return n > 0 && (1162261467 % n == 0);
}
};