@@ -0,0 +1,1725 @@
+/**%0A * Given an integer, write a function to determine if it is a power of three.%0A */%0Apublic class power_of_three %7B%0A%0A    /**%0A     * SOLUTION%0A     */%0A    public static boolean isPowerOfThree(int n) %7B%0A        if (n == 0) return false;%0A        while (n %25 3 == 0) %7B%0A            n /= 3;%0A        %7D%0A        return n == 1;%0A    %7D%0A%0A    /**%0A     * SOLUTION%0A     * Because we have a 32 bit signed int, the choices are fairly short. Because we can't actually store numbers%0A     * larger than 3%5E19 in an int, we only have to check 3%5E0 to 3%5E19 numbers.%0A     */%0A    public static boolean isPowerOfThree2(int n) %7B%0A        return (n == 1) %7C%7C%0A                (n == 3) %7C%7C%0A                (n == 9) %7C%7C%0A                (n == 27) %7C%7C%0A                (n == 81) %7C%7C%0A                (n == 243) %7C%7C%0A                (n == 729) %7C%7C%0A                (n == 2187) %7C%7C%0A                (n == 6561) %7C%7C%0A                (n == 19683) %7C%7C%0A                (n == 59049) %7C%7C%0A                (n == 177147) %7C%7C%0A                (n == 531441) %7C%7C%0A                (n == 1594323) %7C%7C%0A                (n == 4782969) %7C%7C%0A                (n == 14348907) %7C%7C%0A                (n == 43046721) %7C%7C%0A                (n == 129140163) %7C%7C%0A                (n == 387420489) %7C%7C%0A                (n == 1162261467);%0A    %7D%0A%0A    /**%0A     * SOLUTION%0A     * We keep 3%5E19, as its the largest power of three that can be stored in an 32bit int. Since the mod of 3%5E19 to any%0A     * power of 3 is 0, we check if thats the case. If it is and is not 0 (edge case) then it's a power of three.%0A     */%0A    public static boolean isPowerOfThree3(int n) %7B%0A        return (n %3E 0) && (1162261467 %25 n == 0);%0A    %7D%0A%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(isPowerOfThree(387420489));%0A    %7D%0A%7D%0A%0A

Create power_of_three.java