@@ -0,0 +1,1159 @@
+package math;%0A%0Apublic class Q263UglyNumber %7B%0A%0A    //Difficulty: easy%0A    //TAG: math%0A%0A    /**%0A     * 263. Ugly Number%0A     * Write a program to check whether a given number is an ugly number.%0A     *%0A     * Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.%0A     *%0A     * Example 1:%0A     *%0A     * Input: 6%0A     * Output: true%0A     * Explanation: 6 = 2 %C3%97 3%0A     * Example 2:%0A     *%0A     * Input: 8%0A     * Output: true%0A     * Explanation: 8 = 2 %C3%97 2 %C3%97 2%0A     * Example 3:%0A     *%0A     * Input: 14%0A     * Output: false%0A     * Explanation: 14 is not ugly since it includes another prime factor 7.%0A     * Note:%0A     *%0A     * 1 is typically treated as an ugly number.%0A     * Input is within the 32-bit signed integer range: %5B%E2%88%92231,  231 %E2%88%92 1%5D.%0A     */%0A%0A    /*%0A    Solution:%0A%0A    first keep num /= 2 if it could (num %25 2 == 0) keep same as 3 and 5%0A    finally check if num == 1%0A%0A    Time: O(logn)%0A    Space: O(1)%0A     */%0A%0A    public boolean isUgly(int num) %7B%0A        if (num %3C= 0) return false;%0A        while (num %25 2 == 0) num /= 2;%0A        while (num %25 3 == 0) num /= 3;%0A        while (num %25 5 == 0) num /= 5;%0A        return num == 1;%0A    %7D%0A%0A%7D%0A

263. Ugly Number