class Solution {
public static void main(String[] args){
Solution sl = new Solution();
boolean result = sl.isPowerOfThree(27);
System.out.println(result);
}
public boolean isPowerOfThree(int n) {
if(n == 0){
return false;
}
while(true){
if(n == 1){
return true;
}else if(n % 3 == 0){
n = n/3;
}else{
return false;
}
}
}
}