public class Solution {
public boolean isPowerOfThree(int n) {
// 1162261467 is 3^19, 3^20 is bigger than int
return ( n>0 && 1162261467%n==0);
}
}
if n is power of three, then the multiplier of n is also the power of three.So the modulo would be zero definitely. If any part of the number not belonging to the power of three, the modulo will be non-zero.
@MtAdams Man, you're very impressive too ...
3^19 / 3^2 = 3^17, which is a whole number, which means there's no remainder, which is, if interpreted into math language, 3^19 % 3^2 = 0.