An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

Given an integer n, return true if n is an ugly number.

&nbsp;
Example 1:

Input: n = 6
Output: true
Explanation: 6 = 2 × 3


Example 2:

Input: n = 1
Output: true
Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.


Example 3:

Input: n = 14
Output: false
Explanation: 14 is not ugly since it includes the prime factor 7.


&nbsp;
Constraints:


	-231 &lt;= n &lt;= 231 - 1


class Solution:
    def isUgly(self, n: int) -> bool:
        if n == 0:
            return False
        res=[2, 3, 5]
        while n!= 1:
            for i in res:
               if n%i==0:
                   n=n//i
                   break
            else:
                return False
        return True
class Solution {
    public boolean isUgly(int n) {
        if(n==0) return false; //edge case
        while(n!=1){
            if(n%2==0){
               n=n/2;
            }
            else if(n%3==0){
               n=n/3;
            }
            else if(n%5==0){
               n=n/5;
            }
            else{
                return false;
            }
        }
        return true;

    }
}
class Solution {
public:
   bool isUgly(int n)
  {
     if (n <= 0) return false;
     int n1 = 0;
     while(n != n1)
     {
     n1 = n;
     if ((n % 2) == 0) n /= 2;
     if ((n % 3) == 0) n /= 3;
     if ((n % 5) == 0) n /= 5;
     }
     if (n < 7) return true;
     return false;
  }
};
var isUgly = function(n) {
    let condition = true;
    if(n == 0) // 0 has infinite factors. So checking if the number is 0 or not
        return false;
    while(condition){ //applying for true until 2, 3, 5 gets removed from the number
        if(n % 2 == 0)
            n = n / 2;
        else if(n % 3 == 0)
            n = n / 3;
        else if(n % 5 == 0)
            n = n / 5;
        else
        condition = false; //if the number doesnt have 2, 3, 5 in it anymore, this part will execute and will end the while loop
    }
    return n == 1 ? true : false;//checking if the number only had 2, 3, 5 in it or had something else in it as well
};
Ugly Number